c# - Problems validating Regex.IsMatch -
i have problem regx.ismatch
. need validate string in format, @"[o]-[0-9]{8}-[0-9]{5}-[0-9]-[0-9]-[0-9]"
, using code:
if (!regex.ismatch(vm.cadastralnumber, @"[o]-[0-9]{8}-[0-9]{5}-[0-9]-[0-9]-[0-9]")) modelstate.addmodelerror("cadastralnumber", "prefix should o, or format not correct"); .
but got problem, after format need user not allow write more number -[0-9]-[0-9]-[0-9]-[0-9]
. never stops, need users write format gave first, ad not alow writting more -. help?
write @"^[o]-[0-9]{8}-[0-9]{5}-[0-9]-[0-9]-[0-9]$"
make regex match beginning (^
) , end ($
) of string.
Comments
Post a Comment