ASP. Net front-end data validation and asp.net 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>