Thursday, March 22, 2012

Mask and Validation Expression

Hi:

I am not sure what I am doing wrong. I am trying to validate postal code.

My mask is (letter digit letter space digit letter digit)

9L9 L9L

I tried various validation expressions in my masked edit validator eg as follow:

[ABCEGHJKLMNPRSTVXY]\d[A-Z] *\d[A-Z]\d

When I enter the correct it considers it invalid (InvalidValueBlurredMessage - and invalid value message is displayed). Can you help?

[ABCEGHJKLMNPRSTVXY]\d[A-Z] *\d[A-Z]\d

i dont know what "mask" is but the visual studio validation expression is

\d{6}

for postal code, and if youre using studio then you can just put a regular expression validator down set it to rpc postal code and BAM awesome validation


Hello,

You said: "letter digit letter space digit letter digit", but you type 9L9 L9L - which is actually "digit letter digit space letter digit letter"?

Also in your example the user should enter only uppercase letters, and have in mind that "\s" is for space.

Regards


Here's a regular expression that matches 9L9 L9L:

^\d{1}[A-Za-z]{1}\d{1}\s{1}[A-Za-z]{1}\d{1}[A-Za-z]{1}$

Maybe there's a better way of doing it, but

You can test out regular expressions athttp://www.nregex.com/nregex/default.aspx .


Hi:

Thanks - I changed the property "Clear on lost focus" to false - and it works now. My problem I believe, had to do with the space in the mask which was disappering when Clear Mast on Lost Focus was set to true. And you are right, I needed to enter, according to my mask capital letter. Thanks again.


Hi thanks so much. The problem had to do with the space and the mask. I got it working now.


can you explain what the mask is?


Hi:

It is a pattern of characters that users has to enter (at the time of entry-property of the masked edit validator), eg. L9L 9L9 will force user to enter a character, digit, character, etc. Extended validator has also built in data input formats (mask types) eg. date, number, time, date-time, etc.

Thanks.


i use validators and expressions and inputs and such but ive never heard them called masks, where does that come from?


I use Ajax Masked Edit Extenders but you I think you can also use ASP.net server input mask controls.


The correct regular expression is

^\d[a-zA-Z]\d [a-zA-Z]\d[a-zA-Z]$


Just a tip, if its a public website, make sure you RegEx your input on your code-behinds as well, dont rely on the client side code only

0 comments:

Post a Comment