0

I am writing a search module where i need to restrict user from entering search string start with wildcard using custom validator like

*apple, *?apple, ?apple, **apple, ??apple etc

Any help would be greatly appreciated.

Thanks

Toto
  • 89,455
  • 62
  • 89
  • 125
Asp.Net Dev
  • 135
  • 1
  • 3
  • 10
  • Wouldn't it be better to not limit the user, but escape his text before passing it on? If you're using Regex, you could use Regex.Escape (See: http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.escape.aspx) or SQL Like (see: http://stackoverflow.com/questions/1428197/how-to-escape-a-string-for-use-with-the-like-operator-in-sql-server) – jessehouwing Mar 21 '12 at 14:02

2 Answers2

0

How about:

^[^*?]

This will match a string that doesn't begin with * or ?

Toto
  • 89,455
  • 62
  • 89
  • 125
0

What about using a validation expression like

^[a-zA-Z].*$

i.e. allowing only a letter as first character, or

^[^\*\?].*$

i.e. anything that is not a * or ? as first character.

Paolo Tedesco
  • 55,237
  • 33
  • 144
  • 193