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

Help with regular expression

Last post 05-13-2008, 4:53 PM by Lyndar. 3 replies.
Sort Posts: Previous Next
  •  05-13-2008, 3:54 PM 42205

    Help with regular expression

    Hi, Can any help me with forming this regular expression

    Need to check for the values falling in this criteria and flag them. meaning if place this in validator.xml (Struts Framework), i should be able to check for the condition if form value doesnot belong to the below mentioned criteria return true. 

    N (numeric) (numeric) (numeric) (numeric) (numeric)
    N (numeric) (numeric) (numeric) (numeric) (alpha)
    N (numeric) (alpha) (anything in the last 3 characters)
    NM (anything)
    NY (anything)
    NT (anything)
    N (alpha or numeric) and ends with 1234 

    Thanks

  •  05-13-2008, 4:00 PM 42207 in reply to 42205

    Re: Help with regular expression

    I'm not familiar with Struts, but this may help:

    N\d{5} = N followed by 5 digits

    N\d{4}[a-z] = N followed by 4 digits and a single letter

    N\d[a-z].{3} = N followed by a digit a letter and 3 characters of any kind.

     

  •  05-13-2008, 4:13 PM 42208 in reply to 42207

    Re: Help with regular expression

    This is how i wrote it, if you can give me better one that would be greate 

    ([nN][0-9]{5,})|([nN][0-9][0-9][0-9][0-9][a-zA-Z])|([nN][0-9][a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z])|([nNmM][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z])|([nNyY][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z])|([nNtT][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z][0-9a-zA-Z])|([nN][0-9a-zA-Z][4][3][0][2])

  •  05-13-2008, 4:53 PM 42210 in reply to 42208

    Re: Help with regular expression

    I shrunk the regex a little bit:

    ([nN]\d{5,})|([nN]\d{4}[a-zA-Z])|([nN]\d[a-zA-Z][\da-zA-Z][\da-zA-Z][\da-zA-Z])|([nNmM][\da-zA-Z][\da-zA-Z][\da-zA-Z][\da-zA-Z])|([nNyY][\da-zA-Z][\da-zA-Z][\da-zA-Z][\da-zA-Z])|([nNtT][\da-zA-Z][\da-zA-Z][\da-zA-Z][\da-zA-Z])|([nN][\da-zA-Z]4302)

    If you have an option for case insensitive matching, you can replace your [a-zA-Z] with just [a-z], and your [nNmM] with [nm] or [NM]

View as RSS news feed in XML