Determine if it is a URL
<script language= "JavaScript" >
function Checkuserinfo () {
var Homepage=userinfo.homepage.value;
if (homepage== "") {
Alert ("Please enter your homepage address!") ");
Document.userinfo.homepage.focus ();
}else{
if (!checkeurl (homepage)) {
Alert ("The personal page address you entered is not legal!") ");
Document.userinfo.homepage.focus ();
Return
}
}
Userinfo.submit ();
}
function Checkeurl (URL) {
var Str=url;
In JavaScript, regular expressions can only start and end with "/" and cannot use double quotation marks
The regular expression that determines the URL address is: http (s)?:/ /([\w-]+\.) +[\w-]+ (/[\w-./?%&=]*)?
The escape character "\" is applied in the following code 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>
Mailbox Detection —————————————————————————— 4
function Check_idea15 (s)
{
var reemail=/^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/;
var b_email=reemail.test (s);
if (B_email)
{
$ ("Span_15″"). Innerhtml= "}
Else
{
$ ("Span_15″"). Innerhtml= " mailbox Unavailable";
}
}
User Information Detection —————————————————————————— 4
function Check_password (obj) {
var pwd=$ ("Password"). Value;
var rechinese=/[\u0391-\uffe5]+/;
var b_chinese=rechinese.test (PWD);
var respace=/\s+/;
var b_space=respace.test (PWD);
——-length Test
if (pwd.length<6) {
$ ("Span_password"). Innerhtml= " Password length cannot be less than 6 ″;
flag4[1]=0;
CHECK_DATA4 ();
}
——-legality detection: cannot contain Chinese characters
else if (B_chinese) {
$ ("Span_password"). Innerhtml= " Password cannot contain Chinese";
flag4[1]=0;
CHECK_DATA4 ();
}
——-legality detection: cannot contain spaces
else if (b_space) {
$ ("Span_password"). Innerhtml= " Password cannot contain spaces";
flag4[1]=0;
CHECK_DATA4 ();
}
Show password strength when ——-legal
else{
Define the corresponding message prompt
var num=getresult (PWD);
var msg=new Array (" Password strength difference", " Password strength General", " Password strength Strong ");
$ ("Span_password"). Innerhtml=msg[num];
if ($ ("Password"). value!= "") {
Check_vpassword ();
}
return flag4[1]=1;
CHECK_DATA4 ();
}
}
Define the detection function, return 0/1/2 respectively for poor/general/strong
function GetResult (s) {
var ls =-1;
if (S.match (/[a-z]/ig)) {
ls++;
}
if (S.match (/[0-9]/ig)) {
ls++;
}
if (S.match (/(. [ ^a-z0-9]) (/ig)) {
ls++;
}
return LS;
}
——— Password Consistency detection
function Check_vpassword () {
var pwd=$ ("Password"). Value.tostring ();
var check_pwd=$ ("Vpassword"). Value.tostring ();
if (flag4[1]==1) {
if (pwd==check_pwd) {
$ ("Span_vpassword"). Innerhtml= " password can be used";
Flag4[2]=1;
CHECK_DATA4 ();
}
else{
$ ("Span_vpassword"). Innerhtml= " Two times the password is not the same";
flag4[2]=0;
CHECK_DATA4 ();
}
}
}
#//Verify whether it is empty
# function Check_blank (obj, obj_name) {
# if (Obj.value! = ") {
# return true;
#}else{
# alert (obj_name + "Fill cannot be empty! ");
# obj.value = "";
# return false;
# }
# }
#
#//Filter the length of the input characters
# function Check_str_len (name,obj,maxlength) {
# Obj.value=obj.value.replace (/(^\s*) | ( \s*$)/g, "");
# var newvalue = Obj.value.replace (/[^\x00-\xff]/g, "* *");
# var length11 = newvalue.length;
# if (length11>maxlength) {
# alert (name+ "length cannot exceed" +maxlength+ "characters! ");
# obj.value= "";
# Obj.focus ();
# }
# }
#
#//Verify only for digital
# function CheckNumber (obj) {
# var reg =/^[0-9]+$/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# alert (' Only enter numbers! ‘);
# obj.value = "";
# Obj.focus ();
# return false;
# }
# }
#
#//Verify the range of the number size
#
# function Check_num_value (obj_name,obj,minvalue,maxvalue) {
# var reg =/^[0-9]+$/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# alert (obj_name+ ') can only enter numbers! ‘);
# obj.value = "";
# Obj.focus ();
# return false;
#}else if (minvalue>obj.value| | Obj.value>maxvalue) {
# alert (obj_name+ "range is" +minvalue+ "-" +maxvalue+ "!);
# obj.value= "";
# Obj.focus ();
# return false;
# }
#
# }
#
#//verification can only be letters and numbers
# function Checkzmornum (zmnum) {
# var zmnumreg=/^[0-9a-za-z]*$/;
# if (zmnum.value!= "" &&!zmnumreg.test (Zmnum.value)) {
# alert ("Only input is letters or numbers, please re-enter");
# zmnum.value= "";
# Zmnum.focus ();
# return false;
# }
# }
#
#//Verify double-precision numbers
# function Check_double (obj,obj_name) {
# var reg =/^[0-9]+ (\.[ 0-9]+)? $/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# alert (obj_name+ ' must be a valid double-precision number ');
# obj.value = "";
# Obj.focus ();
# return false;
# }
# }
#
#
#//check box select all
# function Checkboxs_all (obj,cname) {
# var checkboxs = Document.getelementsbyname (cName);
# for (Var i=0;i<checkboxs.length;i++) {
# checkboxs[i].checked = obj.checked;
# }
# }
#
#
#//Verify ZIP/Postal Code
# function Check_youbian (obj) {
# var reg=/^\d{6}$/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# alert (' ZIP code format input Error! ‘);
# obj.value = "";
# Obj.focus ();
# return false;
# }
# }
#
#//Verify Mailbox format
# function Check_email (obj) {
# var reg =/^[a-za-z0-9_-]+ (\. ( [a-za-z0-9_-]) +) *@[a-za-z0-9_-]+[.] [A-za-z0-9_-]+ ([.] [a-za-z0-9_-]+] *$/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# obj.select ();
# alert (' e-mail format input Error! ‘);
# obj.value = "";
# Obj.focus ();
# return false;
# }
# }
#
#/* Verify fixed phone number
# 0\d{2,3} represents the area code
# [0\+]\d{2,3} represents the international area code
# \d{7,8} stands for 7-8 digits (indicates phone number)
# correct format: Area code-Phone number-extension (full write | write phone number only)
# */
#
# function Check_phone (obj) {
# var reg=/^ ([0\+]\d{2,3}-)? ( 0\d{2,3})? (\d{7,8}) (-(\d{3,}))? $/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# alert (' Phone number format input Error! ‘);
# obj.value = "";
# Obj.focus ();
# return false;
# }
# }
#
#//Verify the mobile phone number (check the phone number at the beginning of 13,15,18!) )
# function Check_telephone (obj) {
# var reg=/^[1][358]\d{9}$/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# alert (' Phone number format input Error! ‘);
# obj.value = "";
# Obj.focus ();
# return false;
# }
# }
#
#//Verify whether it is in Chinese
# function Ischinese (obj,obj_name) {
# var reg=/^[\u0391-\uffe5]+$/;
# if (obj.value!= "" &&!reg.test (Obj.value)) {
# alert (obj_name+ ' must input Chinese! ‘);
# obj.value = "";
# Obj.focus ();
# return false;
# }
# }
#
#//Determine if it is IE browser
#
# function Checkisie () {
# if (-[1,]) {
# alert ("This is not IE browser! ");
#}else{
# alert ("This is IE browser! ");
# }
# }
#
#//Verify that the URL is correct
# function Check_isurl (obj) {
#
#
# }
#
#//test time size (compared to current time)
# function Checkdate (obj,obj_name) {
# var obj_value=obj.value.replace (/-/g, "/");//replacement character, changed to standard format (check format: ' 2009-12-10 ')
#//Var obj_value=obj.value.replace ("-", "/");//replacement character, changed to standard format (check format: ' 2010-12-10 11:12 ')
# var date1=new Date (Date.parse (Obj_value));
# var date2=new date ();//Take Today's Day
# if (date1>date2) {
# alert (obj_name+ "cannot be greater than the current time!) ");
# return false;
# }
# }