You often need to verify the email address, mobile phone number, and phone number. Here, record the regular expression verification implementation in ASP
Function validate (byval STR, byval number)
Dim temp, Reg
Set Reg = new Regexp
Reg. ignorecase = true
Reg. Global = true
Select case CSTR (number)
'English + Space
Case "0" temp = "^ [A-Za-Z] + $"
'Number + horizontal bars
Case "1" temp = "^ [0-9 \-] + $"
'Halfwidth Digit
Case "2" temp = "^ \ D + $"
'Email address
Case "3" temp = "^ \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W +) * $"
'Mobile Phone Number Format
Case "4" temp = "^ (13 [0-9] {1}) | 159 | 153) + \ D {8}) $"
'Phone number format 1
Case "5" temp = "^ ([0 \ +] \ D {2, 3 }-)? (0 \ D {2, 3 })-)? (\ D {7, 8}) (-(\ D {3 ,}))? $"
'Phone number format 2
Case "6" temp = "^ ([0 \ +] \ D {2, 3 }-)? (0 \ D {2, 3 }))? (\ D {7, 8}) (-(\ D {3 ,}))? $"
Case else temp = Number
End select
Reg. pattern = temp
Validate = reg. Test (TRIM (STR ))
Set Reg = nothing
End Function
Method:
If validate (Tel, 4) or validate (Tel, 5) or validate (Tel, 6) then
Else
Response. Write ("<script language = 'javasComment '> alert ('Check your contact number or mobile phone number format! '); History. Back () </SCRIPT> ")
Response. End ()
End if