How do i restrict users to type only 4 numeric values in a textbox in asp.net? I need to use the regular expression validation please help
-
1i don't know what to do, i am really novice in regular expressionsuser1400158– user14001582012-07-07 11:24:02 +00:00Commented Jul 7, 2012 at 11:24
-
That's fair enough, but SO helpers are just that, helpers, they won't tend to do tasks in their entirety. Please have a look into some basic REGEX tutorials and attempt something, then we can help. [EDIT - @buring_LEGION has just completely blown me out of the water with an answer, so...]Mitya– Mitya2012-07-07 11:27:01 +00:00Commented Jul 7, 2012 at 11:27
-
sorry for a bad question (Maybe) i am new in hereuser1400158– user14001582012-07-07 11:29:10 +00:00Commented Jul 7, 2012 at 11:29
Add a comment
|
4 Answers
Try this for asp.net
<asp:TextBox runat="server" ID="txt" />
<asp:RegularExpressionValidator runat="server"
ID="reg1" ValidationGroup="save" ControlToValidate="txt"
ValidationExpression="^\d{4}$" ErrorMessage="Not 4 digits" />
<asp:Button runat="server" ID="Btn" Text="Clicker" ValidationGroup="save" />
1 Comment
yogi
It would accept blank and four digits only, try it by entering any other than these values.
Pete its very simple. in validation expression just type ^\d{4}$. you will be done.
3 Comments
Shezi
how have you done so far? you got a textbox, and a regular expression validator on ur webform. right? in regular expression validation properties, find ValidationExpression and just typpe " ^\d{4}$ " without quotes and u'll be done
we can write our own regex too. For onfo visit this link
if this regex is match ^\d{4}$ then user input only 4 digit
1 Comment
burning_LEGION
my regex match lonely 4 digit in string, if string contains something else regex does not match