Wednesday, April 6, 2011

RegularExpressionValidator Expression needed

Hi all, i am using asp.net 3.5 and VB.net, i need a validation expression to validate a string of 1 to 50 characters, white spaces, numbers, special character are all allowed, simply, it should match an nvarchar(50) database field. it will be applied to a textbox, also, the same case but for 1-200 characters which will be validating a multi-line textbox..

Thanks in advance

From stackoverflow
  • Do you mean that it just needs to ensure that there are between 1 and 50/200 characters in the strings?

    If so, try these:

    ^[\s\S]{1,50}$
    ^[\s\S]{1,200}$
    

    Testing for [\s\S] rather than [.] ensures that any newlines in the multiline textarea don't cause problems.

    Maen : Yes, also i am accepting any character that can be stored in an nvarchar database field.
  • Have you looked at the following site which provides extensive tutorials and examples on regular expressions :-

    http://www.regular-expressions.info/

0 comments:

Post a Comment