Home > Web Front-end > JS Tutorial > js set of validation functions_form effects

js set of validation functions_form effects

WBOY
Release: 2016-05-16 18:57:25
Original
1001 people have browsed it
Copy code The code is as follows:

//Character processing;
//Remove left and right spaces;
function trim(s){
return rtrim(ltrim(s));
}
//Remove left space;
function ltrim(s){
return s.replace( /^s*/, "");
}
//Remove right space;
function rtrim(s){
return s.replace( /s*$/, "");
}
//Verification information;
//Empty character value;
function isEmpty(s){
s = trim(s);
return s.length == 0 ;
}
//Email;
function isEmail(s){
s = trim(s);
var p = /^[_.0-9a-z-] @ ([0-9a-z][0-9a-z-] .){1,4}[a-z]{2,3}$/i;
return p.test(s);
}
//Number;
function isNumber(s){
return !isNaN(s);
}
//Color value;
function isColor(s){
s = trim(s);
if (s.length !=7) return false;
return s.search(/#[a-fA-F0-9]{6}/) != -1 ;
}
//Mobile phone number;
function isMobile(s){
s = trim(s);
var p = /13d{9}/;
return p .test(s);
}
//ID card;
function isCard(s){
s = trim(s);
var p = /^d{15}( d{2}[xX0-9])?$/;
return p.test(s);
}
//URL;
function isURL(s){
s = trim(s).toLowerCase();
var p = /^http://[A-Za-z0-9] .[A-Za-z0-9] [/=?%-&_~`@ []': !]*([^<>""])*$/;
return p.test(s);
}
//Phone;
function isPhone( s){
s = trim(s);
var p = /^(((d{3}))|(d{3}-))?((0d{2,3})| 0d{2,3}-)?[1-9]d{6,7}$/;
return p.test(s);
}
//Zip;
function isZip (s){
s = trim(s);
var p = /^[1-9]d{5}$/;
return p.test(s);
}
//Double;
function isDouble(s){
s = trim(s);
var p = /^[- ]?d (.d )?$/;
return p.test(s);
}
//Integer;
function isInteger(s){
s = trim(s);
var p = /^[- ]?d $/;
return p.test(s);
}
//English;
function isEnglish(s){
s = trim(s);
var p = /^[A-Za-z] $/;
return p.test(s);
}
//Chinese;
function isChinese(s){
s = trim( s);
var p = /^[u0391-uFFE5] $/;
return p.test(s);
}
//Double byte
function isDoubleChar(s) {
var p = /^[^x00-xff] $/;
return p.test(s);
}
//Contains Chinese characters
function hasChineseChar(s){
var p = /[^x00-xff]/;
return p.test(s);
}
function hasAccountChar(s){
var p = /^[a- zA-Z0-9][a-zA-Z0-9_-]{0,15}$/;
return p.test(s);
}
function limitLen(s,Min,Max ){
s=trim(s);
if(s=="") return false;
if((s.lengthMax))
return false;
else
return true;
}
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