how to put validation for city or state text box using mvc razor or jquery
ex: city text box has to accept only strings and it has to allow space like "andhra pradesh"
Hi chandu512,
Please refer below Sample.
<input type="text" id="txtState" /> <input type="button" id="btnValidate" value="Submit" /> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $("#btnValidate").live("click", function () { var regex = /^[a-zA-Z ]*$/; if (regex.test($("#txtState").val())) { alert("Valid"); } else { alert("Invalid"); } }); </script>
Demo
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.