JQuery Regular Expressions

Source: Internet
Author: User

JQuery Regular Expressions

[Guide]This article provides a large number of jQuery regular expressions, including phone numbers, passwords, usernames, email addresses, and haokeng characters. For more information, see. The Code is as follows: copy the Code <! DOCTYPE html PUBLIC "-W3C dtd xhtml 1 0 Transi

This article provides a large number of jQuery regular expressions, including phone numbers, passwords, usernames, email addresses, and haokeng characters. For more information, see.

 

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Test </title>
<Script type = "text/javascript" language = "javascript" src = "jquery. js"> </script>
<Script type = "text/javascript" language = "javascript">
Function validata (){
If ($ ("# username"). val () = ""){
Document. write ("enter a name ");
Return false;
}
If ($ ("# password"). val () = ""){
Document. write ("enter the password ");
Return false;
}
If ($ ("# telephone"). val () = ""){
Document. write ("Enter your phone number ");
}
If ($ ("# email"). val () = ""){
$ ("# Email"). val ("shuangping@163.com ");
}
}

Function isInteger (obj ){

Reg =/^ [-+]? D + $ /;
If (! Reg. test (obj )){
$ ("# Test" example .html ("<B> Please input correct figures </B> ");
} Else {
$ ("# Test" pai.html ("");
}
}
Function isEmail (obj ){
Reg =/^ w {3,} @ w + (. w +) + $ /;
If (! Reg. test (obj )){
$ ("# Test" pai.html ("<B> enter the correct email address </B> ");
} Else {
$ ("# Test" pai.html ("");
}
}
Function isString (obj ){
Reg =/^ [a-z, A-Z] + $ /;
If (! Reg. test (obj )){
$ ("# Test" ).html ("<B> only characters can be entered </B> ");
} Else {
$ ("# Test" pai.html ("");
}
}
Function isTelephone (obj ){
Reg =/^ (d {3, 4 }-)? [1-9] d {6, 7} $ /;
If (! Reg. test (obj )){
$ ("# Test" 2.16.html ("<B> enter the correct phone number! </B> ");
} Else {
$ ("# Test" pai.html ("");
}
}
Function isMobile (obj ){
Reg =/^ (+ d {2, 3 }-)? D {11 }$ /;
If (! Reg. test (obj )){
$ ("# Test" ).html ("enter the correct mobile phone number ");
} Else {
$ ("# Test" pai.html ("");
}
}
Function isUri (obj ){
Reg =/^ http: // [a-zA-Z0-9] +. [a-zA-Z0-9] + [/=? % -&_~ '@ []': +!] * ([^ <> ""]) * $ /;
If (! Reg. test (obj )){
$ ("# Test" cmd.html ($ ("# uri"). val () + "enter the correct inernet address ");
} Else {
$ ("# Test" pai.html ("");
}
}

// The document is loaded and executed.
$ (Document). ready (function (){
// Do something here

// The color change function of the line.
$ ("P"). each (function (I ){
This. style. color = ['red', 'green', 'blue', 'black'] [I % 2]
});

// Obtain the 3rd elements of the $ ("p") set using eq (2)
$ ("P"). eq (2). click (function () {$ ("# display" ).css ("color", "blue ")});

// All p values in test are appended with the style "over ".
$ ("# Test> p"). addClass ("over ");

// The Last p in test attaches the style "out ".
$ ("# Test p: last"). addClass ("out ");

// Select the same level element.
// $ ('# Faq'). find ('dd'). hide (). end (). find ('dt'). click (function ()

// Select the parent Element
$ ("A"). hover (
Function () {$ (this). parents ("p"). addClass ("out ")},
Function () {$ (this). parents ("p"). removeClass ("out ")})


// Hover effect, toggle switches the function to be called each time you click,
// Trigger (eventtype): triggers an event on each matching element,
// Bind (eventtype, fn), unbind (eventtype): Event binding and anti-binding Delete binding events from each matching element.

// Method concatenation
$ ("# Display"). hover (function (){
$ (This). addClass ("over ");
}, Function (){
$ (This). removeClass ("over ");
})
. Click (function () {alert ($ ("# display"). text ())});




If ($. browser. msie) {// judge the browser. if it is ie, execute the following functions:

// Focus
$ ("Input [@ type = text], textarea, input [@ type = password]")
.Focus(function({{}}(this}.css ({background: "white", border: "1px solid blue "})})
// You can also write data in this way,
// .Blur(function({%}(this%.css ({background: "white", border: "1px solid black "})})

// Lose focus
// You can use addClass () to add css styles.
$ ("Input [@ type = text], textarea, input [@ type = password]")
.Blur(function(){((this).css ({background: "white", border: "1px solid black "});});
}

});



</Script>
<Style type = "text/css">
. Over {
Font-size: large;
Font-style: italic;
}
. Out {
Font-size: small;
}
</Style>
</Head>

<Body>
<Div id = "display"> demo </div>
<Div id = "test">
<P> adfa <a> dfasfa </a> sdfasdf </p>
<P> adfadfasfasdfasdf </p>
<P> adfadfasfasdfasdf </p>
<P> adfadfasfasdfasdf </p>
</Div>
<Form id = "theForm">
IsString <div> <input type = "text" id = "username" onblur = "isString (this. value)"/> </div>
IsInteger <div> <input type = "text" id = "password" onblur = "isInteger (this. value)"/> </div>
IsTelephone <div> <input type = "text" id = "telephone" onblur = "isTelephone (this. value)"/> </div>
IsMobile <div> <input type = "text" id = "mobile" onblur = "isMobile (this. value)"/> </div>
IsEmail <div> <input type = "text" id = "email" onblur = "isEmail (this. value)"/> </div>
IsUri <div> <input type = "text" id = "uri" onblur = "isUri (this. value)"/> </div>
<Div> <input type = "button" value = "Validata" onclick = "return validata ();"/> </div>
</Form>
</Body>
</Html>

 

Address: http://www.php100.com/html/program/jquery/2013/0905/5847.html

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.