From: http://www.80diy.com/home/20050610/22/4074541.html
Common JavaScript verification functions
// Determine whether it is a floating point number.
Function isfloat (s)
{
VaR patrn =/^ [0-9] {1} ([0-9] | [.]) {0, 19} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Check whether it is composed of digits
Function isdigit (s)
{
VaR patrn =/^ [0-9] {1, 20} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Check Logon Name: You can enter only 5-20 strings starting with a letter, which can contain numbers, "_", and ".".
Function isregisterusername (s)
{
VaR patrn =/^ [A-Za-Z] {1} ([a-zA-Z0-9] | [. _]) {} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Check user name: only 1-30 strings starting with letters can be entered
Function istruename (s)
{
VaR patrn =/^ [A-Za-Z] {1, 30} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Password verification: only 6-20 letters, numbers, and underscores can be entered
Function ispasswd (s)
{
VaR patrn =/^ (/W) {6, 20} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Verify the phone number and fax number. The phone number can start with "+" and contain "-" in addition to numbers.
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.exe C (s) return false
Return true
}
// Verify the mobile phone number. It must start with a number and can contain "-" in addition to a number.
Function ismobil (s)
{
VaR patrn =/^ [+] {0, 1} (/d) {1, 3} []? ([-]? (/D) | []) {1, 12}) + $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Verify the zip code
Function ispostalcode (s)
{
// Var patrn =/^ [a-zA-Z0-9] {3, 12} $ /;
VaR patrn =/^ [a-zA-Z0-9] {} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Verify the search keyword
Function issearch (s)
{
VaR patrn =/^ [^ '~! @ # $ % ^ & * () + = | //] [/]/{/}:;/'/,. <>/?] {1} [^ '~! @ $ % ^ & () + = | //] [/]/{/}:;/'/,. <>?] {0, 19} $ /;
If (! Patrn.exe C (s) return false
Return true
}
Function isip (s) // By zergling
{
VaR patrn =/^ [0-9.] {1, 20} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Extract the leading and trailing spaces of the string
VaR strstring = "AAAAA ";
Strstring = strstring. Replace (/(^ [/S] *) | ([/S] * $)/g ,"");