1

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?

Nick
  • 7,475
  • 18
  • 77
  • 128
  • "English characters" is an ambiguous specification. Is "6" an "English character"? What about "é"? (Before you say no, consider words like café, resumé, fiancé, et cetera.) You're going to need to be more specific. – John Feminella Jan 17 '10 at 15:41
  • Not only what @John Feminella already stated but also all the punctuation characters. Is such a symbol as "™" to be considered part of the English characters? – Miguel Ventura Jan 17 '10 at 15:44
  • @John - For the purpose of validating this textbox, yes 6 is an English character. @Miguel - Yes TM is a valid character as well. – Nick Jan 17 '10 at 16:25
  • its duplicate question you can get the answer here http://stackoverflow.com/questions/150033/regular-expression-to-match-non-english-characters – GuruKulki Jan 17 '10 at 15:43

3 Answers3

6

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
  • 65,369
  • 27
  • 142
  • 182
  • 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 Jan 17 '10 at 16:01
  • 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. – Nick Jan 17 '10 at 16:32
  • In that case, I would go with Kibbee's answer :-) +1 to Kibbee – IrishChieftain Jan 17 '10 at 17:18
  • 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 Jan 19 '10 at 01:16
0

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
  • 15,108
  • 7
  • 50
  • 91
0

You might use the FilteredTextBox form ASP.NET AJAX.

lmsasu
  • 7,459
  • 18
  • 79
  • 113