Home > Web Front-end > JS Tutorial > body text

Commonly used validation sets for JavaScript forms_javascript skills

WBOY
Release: 2016-05-16 19:06:30
Original
1083 people have browsed it
JavaScript form verification age
JavaScript form verification age, which determines whether an input amount meets the age, is implemented through regular expressions.
//Check age
function isAge(str){
var mydate=new Date;
var now=mydate.getFullYear();
if (str now-18) {
return false;
return true; email, implemented through regular expressions.
//Check email mailbox
function isEmail(str){
var reg = /^([a-zA-Z0-9_-]) @([a-zA-Z0-9_-]) ((.[a-zA-Z0-9_-]{2,3}){1,2})$/; return reg.test(str); }


JavaScript form verification Chinese capital letters

JavaScript form verification Chinese capital letters, determine whether an input is Chinese or capital English letters, implemented through regular expressions.

//Check whether it is a valid real name, which can only contain Chinese or uppercase English letters
function isValidTrueName(strName){ var str = Trim(strName); //Determine whether it is All English uppercase or all Chinese, can contain spaces var reg = /^[A-Z u4E00-u9FA5] $/;
if(reg.test(str)){
return false;
}
return true;
}
JavaScript form verification is Chinese
JavaScript form verification is Chinese, to determine whether an input is Chinese, implemented through regular expressions.

//Check if it is Chinese
function isChn(str){
var reg = /^[u4E00-u9FA5] $/;
if(!reg.test(str)) {
return false;
return true; Phone number, implemented through regular expressions.
//Check phone number
function isTel(str){
var reg=/^([0-9]|[-]) $/g;
if(str.length
18){
return false;
}
else{
return reg.exec(str); } }
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template