Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to check whether the first and the last letters entered in a textbox are digits or not
Posted

You should use the following regular expression against the text box text:

\d.*\d
 
Share this answer
 
Comments
MathewPV 22-Nov-10 23:26pm    
its working thanks
You can use regular expression validator.

XML
<asp:TextBox ID="txtStringFirstLast" runat="server"></asp:TextBox>
               
               
                <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server"
                    ControlToValidate="txtStringFirstLast" ErrorMessage="first and last letter must be digit."
                    ValidationExpression="^\d\w*\d$" ></asp:RegularExpressionValidator>


You can download regular expression builder here to create any regular expression and test it: [http://sourceforge.net/projects/regexbuilder/files/]
 
Share this answer
 
Comments
MathewPV 22-Nov-10 23:26pm    
its working good thanks.
MathewPV 22-Nov-10 23:28pm    
it should allow only "-" in between digits this process is iterative ie.
1-1
12-1-12
12-12-12-12
any number of digits with hyphen in between
virang_21 22-Nov-10 23:35pm    
Yes my solution will work for anything like digit followed by any word followed by digit. It cannot handle spaces in between. If you want spaces use the regex in answer 1. I gave a link to regex builder so try your regex on it and see if it meet your need.
virang_21 23-Nov-10 0:34am    
Change Regular expression to ^\d(\d*[-]\d*)*\d*$

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900