regex - Regular Expression in C# for either empty, 0, or a length 5 digit. (Zip Code) -


i'm stuck on problem. have input field zip code, however, our database has lot of records zip code 0. have regular expression set on field ensure zip either empty or 5 digit value.

because however, if go update record has value set "0", triggers validation message because not empty string or 5 digit string. want make able accept 3 of these states (empty, "0" or 5 digit number).

(^\s{0,5}$)|(^\d{5}$) - i've been using empty or 5 digit number, seems work fine.

(^?:(\s{0}$)|(^?:(0){1}$|\d{5})$) - i've tried empty, "0" or 5 digit number, doesn't work. have next no clue what's going on, barely understand regular expressions. appreciated, thanks!

i go with:

(^([0]|[0-9]{5})$) 

where input 0 or 5 number combination.

as pointed out in comment, regex matching , can't match when there nothing


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -