views:

134

answers:

4

Do I need to use regex to ensure that the user has typed in English? All characters are valid except non English characters.

How do I validate this textbox?

+6  A: 

A regex would work quite well for this. Something like

^[a-zA-Z0-9 ?!.,;:$]*$

would be a good starting point. It would allow all alphabetical and numerical characters, as well as some common punctuation. You would need to change it depending on what your definition of English characters is.

See the regex docs here for more information.

Kibbee
Good regex. Just to add, you could implement this regex using a RegularExpressionValidator and assigning the textbox as the 'ControlToValidate': http://msdn.microsoft.com/en-us/library/eahwtc9e(VS.71).aspx
keyboardP
My definition of english characters are any english alphabets, numbers and symbols. Here's the context of what I am trying to do. I have an app that converts text to a different format. Currently, the plugin I am using supports only english. I need to validate before I pass this through the 3rd party component.
In that case, I would go with Kibbee's answer :-) +1 to Kibbee
IrishChieftain
@Kibbee - Would this regex accept or reject symbols such as Copyright, trademark etc?
Yes it would. Basically, it only allows letters, numbers, space, and ? ! . , ; : You would have to alter it (refer to linked docs) to meet your specific needs.
Kibbee
A: 

its duplicate question you can get the answer here

http://stackoverflow.com/questions/150033/regular-expression-to-match-non-english-characters

GK
may i know the reason for dwonvote
GK
I didn't downvote, but I can see that this is not an *answer*. This should have been a comment.
Jonathan Sampson
A: 

This has nothing to do with regular expressions and the link referred to by gurukulki does not answer the question either. To change language, you need to implement localization in your website:

http://www.west-wind.com/presentations/wwdbResourceProvider/introtolocalization.aspxlink text

http://www.codeproject.com/KB/aspnet/localizationByVivekTakur.aspx

IrishChieftain
A: 

You might use the FilteredTextBox form ASP.NET AJAX.

lmsasu