JS various commonly used forms to verify regular functions (numbers, mailboxes, integers, decimal) dates, etc.
/************************************************
Validating various data formats
*************************************************/
Add to the number,
function Formatnum (v) {
var reg =/(? = (?! b) (DDD) + (?! d)/g;
Return V.replace (Reg, ', ');
}
Length is not 0 (full space is also considered valid)
function Notnull (v) {
return v.length > 0;
}
Validates a floating-point number (must be a full floating-point number or integer, such as 1.0 or 1, not. 1 or 1.)
function C_float (v) {
var reg =/^d+ (. d+)? $/;
return Reg.test (v);
}
validating integers
function C_int (v) {
var reg =/^d+$/;
return Reg.test (v);
}
Verifying mailboxes
function C_mail (v) {
var reg =/^w+ (-w+) | (. w+)) *@[a-za-z0-9]+ ((. | -) [a-za-z0-9]+] *. [a-za-z0-9]+$/;
return Reg.test (v);
}
Verify ZIP code, consisting of 6 digits
function C_postalcode (v) {
return/^d{6}$/.test (v);
}
Verification Code
function C_validatecode (v) {
return/^w{4}$/.test (v);
}
To verify a string in the format "2008-01-01"
Function C_datestr (val) {
if (val = = "") return true; Birthdays are not required
var reg =/^d{4}-d{1,2}-d{1,2}$/;
if (!reg.test (Val)) return false;
var y,m,d;
var date_list = Val.split ("-");
y = eval (date_list[0]);
m = eval (date_list[1]);
D = eval (date_list[2]);
if (y<1 | | m<1 | | m>12 | | d<1 | | y>2900 | | y<1903) return FALSE;
var month_day = [0,31,28,31,30,31,30,31,31,30,31,30,31];
if (D>month_day[m]) {
if (m==2) {
if ((y%100!=0 && y%4==0) | | y%400==0) && d<30)
return true;
}else{
return false;
}
}else return true;
}