Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

regular expression

Last post 10-05-2008, 6:41 PM by Aussie Susan. 1 replies.
Sort Posts: Previous Next
  •  10-05-2008, 3:43 AM 46885

    regular expression

    i want an expression to avoid enter persian character in a textbox

    anyone to help me?

  •  10-05-2008, 6:41 PM 46898 in reply to 46885

    Re: regular expression

    The general regex technique for this type of requirement is either (pseudocode):

    ^(?=[characters_that_you_want]*$).*$

    or:

    ^(?!.*[^characters_to_exclude]).*$

    The first one  uses a forward lookahead to check that all characters from the start ('^') to the end ('$') are characters you want, where as the second uses a negative lookahead to reject the match if any character is one of the ones you want to exclude. The first one is possibly best if you have a small set of acceptable characters and the  text you are checking is not too long. The second is better if you have a small set of unacceptable characters.

    For example, if you want to exclude all digits, then you could use:

    ^(?!.*[^\d]).*$

    or to express the '\d' as a range

    ^(?!.*[^0-9]).*$

    In your case I have no idea what the 'persian characters' are and whether the set of acceptable or unacceptable characters would be smaller.

    Without knowing the regex engine you are using, the language you are programming in or having a sample of text to test, I can't make any further suggestions. However my suggestions do assume that you have variable length positive and/or negative lookaheads available to you - not all regex's allow this.

    Susan

     

View as RSS news feed in XML