Javascript verifies whether the URL entered by the user is null and the format is correct. javascripturl
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function checkUrl (){
Var url = document. getElementById ('url'). value;
If (url = ''){
Alert ('url address cannot be blank ');
Return false;
} Else if (! IsURL (url )){
Alert ('url format should be http://www.bkjia.com ');
Return false;
} Else {
Return true;
}
Return false;
}
Function isURL (str)
{
// Varreg =/[0-9a-zA-z] +. (html | htm | shtml | jsp | asp | php | com | cn | net | com.cn | org) $ /;
// It must contain at least one character. (the last one has at least one character.) and at least one word character. The last character must be a word character or/
Varreg =/w +. (w + | w +/) $ /;
Varisurl = reg. test (str); // The test (str) method is a js correct expression. The built-in object can be directly called.
Returnisurl;
}
</Script>
Copy codeThe Code is as follows:
<Form action = "" method = "post" onsubmit = "checkUrl ();">
URL:
<Input type = "text" name = "url" id = "url" value = "http://www.bkjia.com" onfocus = "this. value ='' "/>
<Br/>
<Input type = "submit" value = "get address" name = "get"/>
<Input type = "submit" value = "download" name = "download"/>
</Form>
PHP checks URL address Validity
The Code is as follows:
Copy codeThe Code is as follows:
<?
Function is_url ($ str ){
Return preg_match ("/^ http: // [A-Za-z0-9] +. [A-Za-z0-9] + [/=? % -&_~ '@ []': +!] * ([^ <> "]) * $/", $ Str );
}
?>
If you want to try a normal method, you can use the file_get_contents () function to verify it.
Verify whether the email format is correct using javascript
If it is correct, you can use regular expression verification to determine whether the database stores user information. Here is an example of a regular expression. It verifies the input box in the Form.
If (document. form1.mail. value = "")
{
Alert ("email cannot be blank ");
Return false;
}
Else
{
Reg =/^ ([a-zA-Z0-9] + [_ | \-| \.]?) * [A-zA-Z0-9] + @ ([a-zA-Z0-9] + [_ | \-| \.]?) * [A-zA-Z0-9] + \. [a-zA-Z] {2, 3} $/gi;
If (! Reg. test (document. form1.mail. value ))
{
Alert ("invalid email ");
Return false;
}
}
How can I use JavaScript to verify whether the entered phone format is correct?
<Input type = "text" id = "phonenum" name = "phonenum" onkeyup = "ChkPhone (this. value)"/>
Function ChkPhone (val)
{
If (val. length <7) return false; // if the number is less than 7 digits, an error is returned.
Var t =/^ 0 \ d {2, 3} \-\ d {7, 8} $/; // area code-Number
If (! T. test (val )){
Alert ('the entered phone number is incorrect! ');
Return false; // an incorrect number error is returned.
}
}
It's just a general look. Write down the specific requirements.