Follow in Twitter & Facebook


Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools


Thursday, September 20, 2012

Disallow space using regular expression validator in asp.net

In this article we will discuss how we can disallow users to enter space while inputing data in asp.net by using Regular Expressions validators in asp.net. Validation controls are very useful in asp.net application development. There are ways to do this using JQuery or JavaScript. But here we will discuss how we can achive that by using Asp.Net validation controls.

Here is the full HTML code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Disallow space using regular expression validator in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox1" ValidationExpression="^\S*$" ForeColor="Red" ErrorMessage="Do not enter space!"></asp:RegularExpressionValidator>
       <br /> <asp:Button ID="btnTest" runat="server" Text="Click to Test"
            onclick="btnTest_Click" />
    </div>
    </form>
</body>
</html>

Now the output will come like below, whenever any user try to enter space.




0 on: "Disallow space using regular expression validator in asp.net"