ASP. Net front-end data validation and front-end Validation

Source: Internet
Author: User

ASP. Net front-end data validation and front-end Validation

Since the prevalence of the MVC framework, data verification has become easier. developers can directly use [RegularExpression (@ "^ \ d + $")] to add features to the attribute to verify the data format. It is really convenient to use someone else's framework, but if you only use someone else's framework, you will become half a waste after a long time. If you take the framework away from you, it becomes a waste. Now, let's proceed to the question: the JavaScript front-end verifies the data format.

Front and back HTML code:

<P id = "ForegroundValidate_Index_Div"> <table> <tr> <td> Email: </td> <input type = "text" id = "ForegroundValidate_Index_Email"/> </td> </tr> <td> mobile phone number: </td> <input type = "text" id = "ForegroundValidate_Index_Phone"/> </td> </tr> <td> quantity: </td> <input type = "text" id = "ForegroundValidate_Index_Count"/> </td> </tr> </table> <input type = "button" id = "ForegroundValidate_Index_Btn" value = "verify" onclick = "ValidateData () "/> </p>

JQuery verification code:

<Script type = "text/javascript"> function ValidateData () {var email = $ ("# ForegroundValidate_Index_Email "). val (); var phone = $ ("# ForegroundValidate_Index_Phone "). val (); var count = $ ("# ForegroundValidate_Index_Count "). val (); // verify email address: @ In the Razor view indicates the @ symbol in the email address. // note the following: here, the regular expression Writing Method and judgment method are different from c # // Regular Expression format:/regular expression/g, g indicates to search for all var regEmail =// \ w + \. \ w +/; var regPhone =/[1-9] \ d {10}/; var regCount =/^ \ d + $/g; if (r EgEmail. test (email) {alert ("the email format is correct! ");} Else {alert (" Incorrect email format! ");} If (regPhone. test (phone) {alert (" mobile phone number format is correct! ");} Else {alert (" Mobile Phone Number Format error! ");} If (regCount. test (count) {alert (" the number format is correct! ");} Else {alert (" quantity format error! ") ;}}</Script>

Related Article

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: 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.