A regular checksum method for JavaScript scripting language

Source: Internet
Author: User

There are many types of regular calibration methods, some may be more complex and difficult to remember, I have listed here a few common methods, convenient query.

//whether the checksum is all made up of numbers
function Isshuzi (s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec (s)) return false
return True
}
//Check Login name: only input5-20start with a letter, with numbers,"_","."the string
function Isregisterusername (s)
{
var patrn=/^[a-za-z]{1} ([a-za-z0-9]|[. _]) {4,19}$/;
if (!patrn.exec (s)) return false
return True
}
//Verify user name: Only input1-30A string that starts with a letter
function Istruename (s)
{
var patrn=/^[a-za-z]{1,30}$/;
if (!patrn.exec (s)) return false
return True
}
//Check Password: only input6-20letters, numbers, underscores
function ispasswd (s)
{
var patrn=/^ (\w) {6,20}$/;
if (!patrn.exec (s)) return false
return True
}
//Verify regular telephone and fax number: Yes"+"In addition to numbers, it can contain"-"
function Istel (s)
{
var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? (\d) {1,12}) +$/;
var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +$/;
if (!patrn.exec (s)) return false
return True
}
//Check mobile phone number: Must start with a number, except the number, can contain"-"
function Ismobil (s)
{
var patrn=/^[+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +$/;
if (!patrn.exec (s)) return false
return True
}
//Verifying zip Codes
function Isyoubian (s)
{
var patrn=/^[a-za-z0-9]{3,12}$/;
var patrn=/^[a-za-z0-9]{3,12}$/;
if (!patrn.exec (s)) return false
return True
}
//Verifying search Keywords
function Issearch (s)
{
var patrn=/^[^ ' [email protected]#$%^&* () +=|\\\][\]\{\}:;\ ' \,.<>/?] {1} [^ ' [email protected]$%^& () +=|\\\] [\]\{\}:;\ ' \,.<>?] {0,19}$/;
if (!patrn.exec (s)) return false
return True
}
function IsIP (s)
{
var patrn=/^[0-9.] {1,20}$/;
if (!patrn.exec (s)) return false
return True
}
Function Isbetween (Val, lo, hi) {
if (Val < lo) | | (val > Hi)) {//val is any value, lo is the minimum value, HI is the highest value

return (false);

}
else {return (true);}//Search for intermediate values (that is, not the maximum or minimum value)
}
// Verify Date

Function IsDate (thestr) {
var the1st = thestr.indexof ('-');
var the2nd = thestr.lastindexof ('-');
if (the1st = = the2nd) {return (false);}
Else {
var y = thestr.substring (0,the1st);
var m = thestr.substring (the1st+1,the2nd);
var d = thestr.substring (the2nd+1,thestr.length);
var maxdays = 31;
if (Isint (m) ==false | | isint (d) ==false | | isint (y) ==false) {
return (false);
Else if (Y.length < 4) {return (false);}
Else if (!isbetween (M, 1,)) {return (false);}
Else if (m==4 | | m==6 | | m==9 | | m==11) maxdays = 30;
Else if (m==2) {
if (y% 4 > 0) maxdays = 28;
Else if (y% = = 0 && y% > 0) maxdays = 28;
Else maxdays = 29;
}
if (Isbetween (d, 1, maxdays) = = False) {return (false);}
Else {return (true);}
}
}
// verify null values

function IsEmpty (str) {
if ((str==null) | | | (str.length==0)) return true;
else return (false);
}
// verifies whether an integer
function Isint (THESTR) {
var flag = true;
if (IsEmpty (THESTR)) {flag=false;}
Else
{for (var i=0; i<thestr.length; i++) {
if (IsDigit (thestr.substring (i,i+1)) = = False) {
Flag = false; Break
}
}
}
return (flag);
}
// Verify Email

function Isemail (THESTR) {
var atindex = thestr.indexof (' @ ');
var dotindex = Thestr.indexof ('. ', Atindex);
var flag = true;
Thesub = thestr.substring (0, dotindex+1)
if ((Atindex < 1) | | (Atindex! = Thestr.lastindexof (' @ ')) | | (Dotindex <atindex + 2) | | (Thestr.length <= thesub.length))
{return (false);}
else {return (true);}
}
"^\\d+$"//nonnegative integer (positive integer + 0)
"^[0-9]*[1-9][0-9]*$"//Positive integer
"^ ((-\\d+) | (0+)) $ "//non-positive integer (negative integer + 0)
"^-[0-9]*[1-9][0-9]*$"//Negative integer
"^-?\\d+$"//Integer
"^\\d+ (\\.\\d+)? $"//non-negative floating-point number (positive floating point + 0)
^ ([0-9]+\\]. [0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\\. [0-9]+) | ([0-9]*[1-9][0-9]*)) $ "//positive floating-point number
"^ ((-\\d+ (\\.\\d+)?) | (0+ (\\.0+)?)) $ "//non-positive floating-point number (negative floating-point number +0)
^ (-([0-9]+\\]. [0-9]*[1-9][0-9]*) | ([0-9]*[1-9][0-9]*\\. [0-9]+) | ([0-9]*[1-9][0-9]*))) $ "//negative floating-point number
^ (-?\\d+) (\\.\\d+)? $ "//floating-point number
"^[a-za-z]+$"//A string consisting of 26 English letters
"^[a-z]+$"//A string consisting of 26 uppercase letters in English
"^[a-z]+$"//String consisting of 26 English letters in lowercase
"^[a-za-z0-9]+$"//string consisting of a number and 26 English letters
"^\\w+$"//A string consisting of numbers, 26 letters or underscores
"^[\\w-]+ (\\.[ \\w-]+) *@[\\w-]+ (\\.[ \\w-]+) +$ "//email address
"^[a-za-z]+://(\\w+ (-\\w+) *) (

Next Introduction to jquery example usage

A regular checksum method for JavaScript scripting language

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.