JS-determine the mobile phone number and zip code
Bytes ----------------------------------------------------------------------------------------------------------------------
<Form id = "form1" name = "form1" method = "post" action = "SurveySave. asp? Action = add "onsubmit =" return CheckInput (); ">
Phone/Mobile: <input class = "input_o" type = "text" name = "txtMobile" id = "txtMobile"/> <br/>
Zip code: <input class = "input_o" type = "text" name = "txtZipCode" id = "txtZipCode"/>
<Input class = "input1" type = "submit" name = "Submit" id = "Submit" value = "& nbsp; "/>
</Form>
<Script type = "text/javascript">
// Phone-mobile phone Verification
String. prototype. Trim = function (){
Var m = this. match (/^ \ s * (\ S + (\ s + \ S +) *) \ s * $ /);
Return (m = null )? "": M [1];
}
String. prototype. isMobile = function (){
Return (/^ (? : 13 \ d | 15 [89])-? \ D {5} (\ d {3} | \ * {3}) $/. test (this. Trim ()));
}
String. prototype. isTel = function ()
{
Return (/^ (\ d {7, 8}) (-(\ d {3 ,}))? $/. Test (this. Trim ()));
}
// Alert display
Function CheckInput ()
{
Var StrInfo = "";
Var StrUserMobile = "";
Var MobileValue = document. getElementById ("txtMobile"). value;
If (MobileValue. length> 0)
{
If (MobileValue. isMobile () | MobileValue. isTel ()){}
Else
{
Alert ("enter the correct mobile phone number or phone number \ n For example: 13916752109 or ");
Document. getElementById ("txtMobile"). focus ();
Return false;
}
}
Else
StrUserMobile + = "Enter the phone number/mobile phone number! ";
If (StrUserMobile! = "")
StrInfo + = StrUserMobile;
If (document. getElementById ("txtZipCode"). value. length = 0)
StrInfo + = "Enter your zip code! ";
Else
{
If (document. getElementById ("txtZipCode"). value. length <6)
StrInfo + = "Incorrect zip code format! ";
Else
{
Var rexTel =/^ [0-9] + $ /;
If (document. getElementById ("txtZipCode"). value. length> 6 & rexTel. test (document. getElementById ("txtZipCode"). value ))
StrInfo + = "Incorrect zip code format! "
}
}
If (StrInfo = "")
Return true;
Else
{
Alert (StrInfo );
Return false;
}
</Script>
Author: nycqwert