HI ,
i want to avoid special characters in text field in mvc application. We can allow combination of both alpthabet but not all Specials.
Ex : Mahesh@# ---is valied
@#@@@@----- It Should not allow.
How we can achieve this one
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(function () { $('#btnCheck').on('click', function () { var string = $('#TextBox1').val(); var alphabet = /([a-zA-Z])+(@|#)*$/; if (alphabet.test(string)) { alert('Valid'); return false; } else { alert('Not Valid'); return false; } }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <input name="TextBox1" type="text" id="TextBox1" /><input type="submit" name="btnCheck" value="Check" id="btnCheck" /> </div> </form> </body> </html>
Demo
© COPYRIGHT 2024 ASPSnippets.com ALL RIGHTS RESERVED.