Question

I currently have the following validation expression for one of my asp.net controls, which ensures the user has entered, what we consider to be a valid UK postcode:

ValidationExpression="^\s*([A-Z]{1,2}[0-9R][0-9A-Z]?\s*[0-9][ABD-HJLNP-UW-Z]{2})\s*$"

This works fine if the user enters their postcode using uppercase, but I'd like it to ignore case and am not sure how to incorporate that into the above expression?

Était-ce utile?

La solution 2

The only simple solution is to put lowercase letters everywhere, i.e.: [0-9A-Za-z]

Other solutions are not always reliable.

Autres conseils

I'd like it to ignore case

Activate the ignore case flag by adding this notation to your regex: i.

Your regex would like this one below:

ValidationExpression="/^\s*([A-Z]{1,2}[0-9R][0-9A-Z]?\s*[0-9][ABD-HJLNP-UW-Z]{2})\s*$/i"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top