Several common string validation in JAVASCRP

Source: Internet
Author: User
Tags mail

<!--writed by ZHONG@IECN 2004.3.26-->





<script language= "JavaScript" >


var reip =/^ ([01]?d{1,2}|2[0-4]d|25[0-5]) (. [01]?d{1,2}|2[0-4]d|25[0-5])) {3}$/; IP


var reeml =/^[w-.] +@[a-z0-9]+ (-[a-z0-9]+)? (. [A-z0-9]+ (-[a-z0-9]+)?) *. [A-z] {2,4}$/i; E-Mail


var Retel =/^ ((d{2,3}-)? d{2,5}-)? [2-9]d{6,7} (-d{2,5})? $/; Telephone number


var rembl =/^13[0135-9]d{8}$/; Mobile phone number


var rehttp =/^http://[a-z0-9]+ (-[a-z0-9]+)? (. [A-z0-9]+ (-[a-z0-9]+)?) *. [A-z] {2,4} (/?| /.+) $/i; HTTP address


var renum =/^-?d+ (. d+)? $/; Numerical


var reidc =/^d{15} (d{2}[a-z0-9])? $/; ID card


</script>





<table>


<tr>


<td align= "right" >IP:</td>


<td><input id= "Ipinput"/><input type= "button" value= "Check" onclick= "alert (reip.test) ); "/> (eg: 123.123.123.123) </td>


</tr>


<tr>


<td align= "right" >E-Mail:</td>


<td><input id= "emailinput" ><input type= "button" value= "Check" onclick= "Alert Reeml.test ( Emailinput.value)); " > (such as:xxx@iecn.net</a></td>


</tr>


<tr>


<td align= "right" > Telephone:</td>


<td><input id= "telinput"/><input type= "button" value= "Check" onclick= "Alert Retel.test ( Telinput.value)); "/> (for example: 86-10-12345678-123) </td>


</tr>


<tr>


<td align= "right" > Mobile phone number:</td>


<td><input id= "mblinput"/><input type= button "value=" Check "onclick=" alert ( Mblinput.value)); "/> (for example: 13012345678) </td>


</tr>


<tr>


<td align= "right" >http address:</td>


<td><input id= "httpinput"/><input type= "button" value= "Check" onclick= "Alert Rehttp.test ( Httpinput.value)); "/> (for example: http://www.iecn.net) </td>


</tr>


<tr>


<td align= "right" > Value:</td>


<td><input id= "numinput"/><input type= "button" value= "Check" onclick= "Alert Renum.test ( Numinput.value)); "/> (for example: 123, 123.4, -0.123) </td>


</tr>


<tr>


<td align= "right" > ID card:</td>


<td><input id= "idcinput"/><input type= button "value=" Check "onclick=" alert ( Idcinput.value)); "/> (for example: 123456197601018888) </td>


</tr>


</table>


<br/><br/>


Description: <br/>


1. The IP address has been rigorously validated; <br/>


2. e-mail Address "@" in front of the part is not very sure, if you want to not "manslaughter", "[W.]" + "Change to [^@]+"; <br/>


3. Telephone number to do the basic strict verification, the international area code, the domestic area code, extension number can have or not, the number of digits as long as 7 or 8 can be without consideration of the specific situation; <br/>


4. Mobile phone number of the current situation to achieve a basic rigorous verification; <br/>


5. The HTTP address type can be changed according to the situation, such as "[Http|ftp]", the domain name part has been as strict as possible validation, the path part did not do any validation. <br/>


6. The numerical value achieves the basic rigorous verification; <br/>


7. The ID card only judges the number of digits (15-bit or 18-bit, 18-bit mantissa allows letters).

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.