//Checksum is all made up of numbers
function IsDigit (s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec (s)) return false
return True
}
//Check login name: Only 5-20 characters beginning with a letter, with numbers, "_", "." Can be entered. 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 1-30 strings beginning with a letter can be entered
function Istruename (s)
{
var patrn=/^[a-za-z]{1,30}$/;
if (!patrn.exec (s)) return false
return True
}
//Check password: Enter only 6-20 letters, numbers, underline
function ispasswd (s)
{
var patrn=/^ (W) {6,20}$/;
if (!patrn.exec (s)) return false
return True
}
//Check regular phone, fax: can "+" start, in addition to the number, 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
}
//Check ZIP/Postal code
function Ispostalcode (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
}
//Verify search keywords
function Issearch (s)
{
var patrn=/^[^ ' [email protected]#$%^&* () +=|\][]{}:; ',. <>/?] {1} [^ ' [email protected]$%^& () +=|\] []{}:; ',. <>?] {0,19}$/;
if (!patrn.exec (s)) return false
return True
}
//Verify whether the IP address
function IsIP (s)//by zergling
{
var patrn=/^[0-9.] {1,20}$/;
if (!patrn.exec (s)) return false
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+) *) (\. ( \w+ (-\w+) *) * (\?\s*)? $ "//url
"^[a-za-z0-9_]*$"
Useful JS Regular Expressions (mobile phone number/IP regular/ZIP/phone, etc.)