|
| |
|
|
GolfMad
Posts: 190 Joined: 3/20/2002 From: UK Status: offline
|
.NET Validation controls - simple alphabetic please - 6/21/2007 6:49:17
Could someone please explain how i set the Range validator so that it just ensures all charecters entered are alphabetic (someones name). Likewise for another field i want to ensure they are numeric, (a telephone number). They do not seem to fit in the Range Validator but none of the ones offerred under the Regular Expression seem to give either. I have tried string, integer but what do i put in the min and max values. This was all so simple with FrontPage forms. I would be grateful to anyone who can tell me how please. Regards Phil
|
|
|
|
WantToLearn
Posts: 109 Joined: 10/19/2002 Status: offline
|
RE: .NET Validation controls - simple alphabetic please - 6/21/2007 12:49:37
The Range Validator seems to work for requiring only numbers. In the case of a telephone number, you may not want a strict numeric requirement because you might want your users to enter dashes or parentheses for area codes. The Regular Expression validator does have "Phone number" options. To only allow the alphabet, you can also use the Regular Expression validator with this custom expression: ^[a-z]*$ I'm not an expert on regular expressions so I'm not sure if the expression above is exactly what you are looking for but in some basic testing, it seems to do the job. Below is the sample markup for a Regular Expression validator with the custom expression.
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator" ValidationExpression="^[a-z]*$"></asp:RegularExpressionValidator>
Here is a link to a great article on the subject: http://www.samspublishing.com/articles/article.asp?p=101137&seqNum=3
|
|
|
|
GolfMad
Posts: 190 Joined: 3/20/2002 From: UK Status: offline
|
RE: .NET Validation controls - simple alphabetic please - 6/21/2007 14:00:36
Thanks very much for trying to help wantolearn. I used the expression but moved the order around so it was the same as other control made by EWD. However, if I type a name in with spaces it errors, saying 'Alpha characters only' which is my error text. Is it possible to tweak it or have I done something wrong please? <asp:RegularExpressionValidator runat="server" ErrorMessage="Alpha characters only" ID="checkalpha" Display="Dynamic" ControlToValidate="Name" ValidationExpression="^[a-z]*$" ></asp:RegularExpressionValidator> Link: http://www.engagepd.com/contact.aspx Thanks Phil
|
|
|
|
WantToLearn
Posts: 109 Joined: 10/19/2002 Status: offline
|
RE: .NET Validation controls - simple alphabetic please - 6/21/2007 15:17:05
Try changing the expression from "^[a-z]*$" to "^[a-z ]*$" (add a space after the z).
|
|
|
|
GolfMad
Posts: 190 Joined: 3/20/2002 From: UK Status: offline
|
RE: .NET Validation controls - simple alphabetic please - 6/23/2007 9:36:27
Thanks very much for that wantolearn. Regards Phil
|
|
|
|
GolfMad
Posts: 190 Joined: 3/20/2002 From: UK Status: offline
|
RE: .NET Validation controls - simple alphabetic please - 6/24/2007 12:34:11
Just thought I would let you know, as you were kind enough to take the trouble of helping me; that the space did not solve the problem. I had posted on another forum in between getting your first reply and as the answer worked I thought it might be useful to share with others: quote:
That is not the purpose of the RangeValidator. It is designed to make sure a value fits between a range of values and not that the control is letters only. You want to use a regex control instead and set the validation expression to validate alpha and not digits. The validation expression is [a-zA-Z]+. That will not allow spaces or numbers. If you want spaces change the expression to ([a-zA-Z]|\s)+. Thanks again though wantolearn. Regards Phil
|
|
|
|
WantToLearn
Posts: 109 Joined: 10/19/2002 Status: offline
|
RE: .NET Validation controls - simple alphabetic please - 6/25/2007 10:24:36
Like I said earlier, I know almost nothing about regular expressions so my answer was just a guess. Glad you found the correct solution and thanks for sharing it.
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|