1. Verification Class
1. Digital verification
1.1 Integer
/^(-|\+)?\d+$/.test(str)
1.2 Integer greater than 0 (for verification of incoming ID)
/^\d+$/.test(str)
1.3 Verification of negative integers
/^-\d+$/.test(str)
2. Time category
2.1 Short time, like (13:04:06)
function isTime(str)
{
var a = (/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
if (a == null) {alert('The input parameter is not the time format'); return false;}
if (a[1]>24 || a[3]>60 || a[4]>60)
{
alert("Time format is incorrect");
return false
}
return true;
}
2.2 Short date, like (2003-12-05)
function strDateTime(str)
{
var r = (/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false;
var d= new Date(r[1], r[3]-1, r[4]);
return (()==r[1]&&(()+1)==r[3]&&()==r[4]);
}
2.3 For a long time, it looks like (2003-12-05 13:04:06)
function strDateTime(str)
{
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
var r = (reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (()==r[1]&&(()+1)==r[3]&&()==r[4]&&()==r[5]&&()==r[6]&&()==r[7]);
}
2.4 Only year and month. Like (2003-05, or 2003-5)
2.5 Only hours and minutes, like (12:03)
3. Form category
3.1 All forms cannot be empty
<input onblur="if((/^\s+|\s+$/g,'')=='')alert('can't be empty!')">
3.2 The value of a multi-line text box cannot be empty.
3.3 The value of a multi-line text box cannot exceed sMaxStrleng
3.4 The value of a multi-line text box cannot be less than sMixStrleng
3.5 Determine whether the radio box is selected.
3.6 Determine whether the check box is selected.
3.7 Select all check boxes, multiple selections, non-select all, reverse selection
3.8 Determine file type during file upload
4. Character Class
4.1 The judgment characters are all composed of a-Z or letters of A-Z
<input onblur="if(/[^a-zA-Z]/())alert('Wrong')">
4.2 Judge the character consists of letters and numbers.
<input onblur="if(/[^0-9a-zA-Z]/())alert('Wrong')">
4.3: Judgment characters consist of letters and numbers, underscores, and dots. The only thing that starts is underscores and letters.
/^([a-zA-z_]{1})([\w]*)$/(str)
4.4 String replacement function.Replace();
5. Browser class
5.1 Determine the browser type
5.2 The version of judging ie
5.3 Determine the resolution of the client
; ;
6. Combination category
6.1 Email judgment.
function ismail(mail)
{
return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}
6.2 Verification of mobile phone number
6.3 Identity card verification
function isIdCardNo(num)
{
if (isNaN(num)) {alert("The input is not a number!"); return false;}
var len = , re;
if (len == 15)
re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
else if (len == 18)
re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);
else {alert("The number of digits entered is incorrect!"); return false;}
var a = (re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var B = ()==a[3]&&(()+1)==a[4]&&()==a[5];
}
else
{
var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var B = ()==a[3]&&(()+1)==a[4]&&()==a[5];
}
if (!B) {alert("The entered ID number "+ a[0] +" the date of birth is incorrect!"); return false;}
}
return true;
}
3.7 Select all check boxes, multiple selections, non-select all, reverse selection
<form name=hrong>
<input type=checkbox name=All onclick="checkAll('mm')">Select all<br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/>
<input type=checkbox name=mm onclick="checkItem('All')"><br/><br/>
<input type=checkbox name=All2 onclick="checkAll('mm2')">Select all<br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
<input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
</form>
<SCRIPT LANGUAGE="java script">
function checkAll(str)
{
var a = (str);
var n = ;
for (var i=0; i<n; i++)
a[i].checked = ;
}
function checkItem(str)
{
var e = ;
var all = eval("."+ str);
if ()
{
var a = ();
= true;
for (var i=0; i<; i++)
{
if (!a[i].checked){ = false; break;}
}
}
else = false;
}
</SCRIPT>
Previous page1234Next pageRead the full text