Using Regular Expression To Validate TextBox

If you want a textbox to only allow its content to be a string matches any alphanumeric string with spaces. You could use the RegularExpressionValidator Control, set its ControlToValidate property to the TextBoxID, and set its ValidationExpression property to ^[A-Za-z0-9,\s]+$

HTML CODE

<asp:RegularExpressionValidator id="RegularExpressionValidator1" style='Z-INDEX: 109; LEFT: 192px; POSITION: absolute; TOP: 96px'
    runat="server" ErrorMessage="RegularExpressionValidator" ValidationExpression="^[A-Za-z0-9,\s]+$" ControlToValidate="TextBox1"></asp:RegularExpressionValidator>

if you don't want to allow a space, you should change the validationexpression property to ^[a-zA-Z0-9]+$

I have found a good reference for regular expressions, check out the below link

Regular Expressions

Best Regards, 

HC

 

Comments

No Comments

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.