Regular Expression Verification Code (letters, numbers, emails, URLs, phone numbers, Chinese characters, and ID card numbers)

Source: Internet
Author: User

<% If request ("check") <> "then
Astr = request ("content ")
Call STR (astr)
End if
Function STR (astr)
AR = CINT (ASC (astr ))
If (65 <= AR and Ar <= 90) or (97 <= AR and Ar <= 122) then
Response. Write "<SCRIPT> alert ('the input string is an English letter !! '); </SCRIPT>"
Else
Response. Write "<SCRIPT> alert ('the input string is not an English letter !! '); </SCRIPT>"
End if
End Function

%>

Check whether the email address is correct on the server.

<%
Function f_regexp (expression, ifstr)
Dim regexp1, matches
Set objexp = new Regexp 'to create a regular expression
Objexp. pattern = expression' Setting Mode
Objexp. ignorecase = true' indicates whether to enable case sensitivity.
Objexp. Global = true' to set global availability
Matches = objexp. Test (ifstr)
F_regexp = matches
End Function
Function checkemail (STR)
Checkemail = f_regexp ("/W + ([-+. ']/W +) * @/W + ([-.] /W + )*/. /W + ([-.] /W +) * ", trim (STR ))
End Function
%>
<%
If request. Form ("e_mail") <> "" then
If cbool (checkemail (request. Form ("e_mail") then
Response. Write ("the email address you entered is correct! ")
Else
Response. Write ("the email address you entered is incorrect! ")
End if
Else
Response. Write ("You have not entered the email address! ")
End if
%>

The client verifies that the email is correct.

<Script language = "JavaScript">
Function check (myform ){
If (myform. e_mail.value = ""){
Alert ("Enter the email address! "); Myform. e_mail.focus (); return;
}
If (! Checkemail (myform. e_mail.value )){
Alert ("the email address you entered is incorrect! "); Myform. e_mail.focus (); return;
}
Myform. Submit ();
}
Function checkemail (email ){
VaR STR = Email;
// In JavaScript, regular expressions can only start and end with "/", but cannot use double quotation marks
VaR expression = // W + ([-+. ']/W +) * @/W + ([-.] /W + )*/. /W + ([-.] /W + )*/;
VaR objexp = new Regexp (expression );
If (objexp. Test (STR) = true ){
Return true;
} Else {
Return false;
}
}
</SCRIPT>

Use regular expression to verify the phone number

<%
Public Function f_regexp (expression, ifstr)
Dim regexp1, matches
Set objexp = new Regexp 'to create a regular expression
Objexp. pattern = expression' Setting Mode
Objexp. ignorecase = true' indicates whether to enable case sensitivity.
Objexp. Global = true' to set global availability
Matches = objexp. Test (ifstr)
F_regexp = matches
End Function
Function checktel (STR)
Checktel = f_regexp ("(/d {3 }-)? /D {8} | (/d {4}-) (/d {7}) ", trim (STR ))
End Function
%>
<%
If request. Form ("tel") <> "then
If cbool (checktel (request. Form ("tel") then
Response. Write ("the phone number you entered is correct! ")
Else
Response. Write ("the phone number you entered is incorrect! ")
End if
Else
Response. Write ("You have not entered the contact number! ")
End if
%>

Verify that the input string is a Chinese character

<Script language = "JavaScript">
Function check (myform ){
If (myform. realname. value = ""){
Alert ("Enter your real name! "); Myform. realname. Focus (); return;
}
If (checkrealname (myform. realname. Value )){
Alert ("the real name you entered is incorrect! "); Myform. realname. Focus (); return;
}
Myform. Submit ();
}
Function checkrealname (realname ){
VaR STR = realname;
// In JavaScript, regular expressions can only start and end with "/", but cannot use double quotation marks
VaR expression =/[^/u4e00-/u9fa5]/;
VaR objexp = new Regexp (expression );
If (objexp. Test (STR) = true ){
Return true;
} Else {
Return false;
}
}
</SCRIPT>

Verify ID number

<Script language = "JavaScript">
Function check (myform ){
If (myform. Number. value = ""){
Alert ("Enter your ID card number and address! "); Myform. Number. Focus (); return;
}
If (! Checkeno (myform. Number. Value )){
Alert ("your ID number is incorrect! "); Myform. Number. Focus (); return;
}
Myform. Submit ();
}
Function checkeno (NO ){
VaR STR = no;
// In JavaScript, regular expressions can only start and end with "/", but cannot use double quotation marks
VaR expression = // d {17} [/d | x] |/d {15 }/;
VaR objexp = new Regexp (expression );
If (objexp. Test (STR) = true ){
Return true;
} Else {
Return false;
}
}
</SCRIPT>

User name and password verified on the client

<Script language = "JavaScript">
Function check (myform ){
If (myform. username. value = ""){
Alert ("Enter the user name! "); Myform. username. Focus (); return;
}
If (! Checkeusername (myform. username. Value )){
Alert ("the user name you entered is invalid! "); Myform. username. Focus (); return;
}
If (myform. pwd. value = ""){
Alert ("enter the password! "); Myform. pwd. Focus (); return;
}
If (! Checkepwd (myform. pwd. Value )){
Alert ("the password you entered is invalid! "); Myform. pwd. Focus (); return;
}
If (myform. pwd1.value = ""){
Alert ("Please confirm the password! "); Myform. pwd1.focus (); return;
}
If (myform. pwd1.value! = Myform. pwd. Value ){
Alert ("the two passwords you entered are inconsistent. Please enter them again! "); Myform. pwd. Focus (); return;
}
Myform. Submit ();
}
Function checkeusername (username ){
VaR STR = username;
// In JavaScript, regular expressions can only start and end with "/", but cannot use double quotation marks
VaR expression =/^ (/W) {3, 10} $ /;
VaR objexp = new Regexp (expression );
If (objexp. Test (STR) = true ){
Return true;
} Else {
Return false;
}
}
Function checkepwd (PWD ){
VaR STR = PWD;
// In JavaScript, regular expressions can only start and end with "/", but cannot use double quotation marks
VaR expression =/^ [A-Za-Z] {1} ([A-Za-z0-9] | [. _]) {5, 19} $ /;
VaR objexp = new Regexp (expression );
If (objexp. Test (STR) = true ){
Return true;
} Else {
Return false;
}
}
</SCRIPT>

Verify that the website is valid

<Script language = "JavaScript">
Function checkuserinfo (){
VaR homepage = userinfo. Homepage. value;
If (homepage = ""){
Alert ("Enter Your Personal Homepage Address! ");
Document. userinfo. Homepage. Focus ();
} Else {
If (! Checkeurl (homepage )){
Alert ("the Personal Homepage Address you entered is invalid! ");
Document. userinfo. Homepage. Focus ();
Return;
}
}
Userinfo. Submit ();
}
Function checkeurl (URL ){
VaR STR = URL;
// In JavaScript, regular expressions can only start and end with "/", but cannot use double quotation marks
// Determine the regular expression of the URL address: http (s )? : // ([/W-] +/.) + [/W-] + (/[/W -./? % & =] *)?
// The following Code applies the Escape Character "/" to output a character "/"
VaR expression =/HTTP (s )? : // ([/W-] +/.) + [/W-] + (// [/W -.//? % & =] *)? /;
VaR objexp = new Regexp (expression );
If (objexp. Test (STR) = true ){
Return true;
} Else {
Return false;
}
}
</SCRIPT>

Verification quantity and amount

<Script language = "JavaScript">
Function checkprice (){
If (form1.dj. value = 0 & form1.dj. value = ""){
Alert ("Enter the unit price! "); Form1.dj. Focus (); form1.dj. Select (); return ;}
If (isnan (form1.dj. Value )){
Alert ("the unit price you entered is not a valid value! "); Form1.dj. Focus (); form1.dj. Select (); return;
}
}
Function checknum (){
If (form1.sl. value = 0 & form1.sl. value = ""){
Alert ("Enter the quantity! "); Form1.sl. Focus (); form1.sl. Select (); return ;}
STR = form1.sl. value;
Len = Str. length;
For (I = 0; I <Len; I ++ ){
X = Str. substr (I, 1 );
If (X! = "1" & X! = "2" & X! = "3" & X! = "4" & X! = "5" & X! = "6" & X! = "7" & X! = "8" & X! = "9 "){
Alert ("the value you entered is not a valid value (Please enter a positive integer )! "); Form1.sl. Focus

(); Form1.sl. Select (); return;
}
}
}
Function aotopay (){
Form1.je. value = form1.sl. Value * form1.dj. value;
If (isnan (form1.je. Value )){
Form1.je. value = 0;
}
}

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.