asp.net - regular expression validate if 5th or 6th character "_" -


i facing problem in asp.net regular expression.

i need validate if 5th or 6th character "-" .

for example

3000-4567, 3000-4568 string , separated , has hyphen. need check if each comma separated string has 5th or 6th character "-".

current regular expression used in system ^((\s*\d{4,4}\s*[,]){1,3}?)?(\s*\d{4,4})*$

currently validating 3000,4567

i've made 2 slight changes regex:

'^((\s*\d{4,5}\s*[/-]){1,3}?)?(\s*\d{4,4})*$' 

changed cardinality of first numeric group {4,5} allow 5 digits numbers (which guess want since dash can sixth character) , changed separator dash. notice slash escape it, since in square brackets dash special character (tho' don't need brackets there).

as alternative, consider splitting string on instances of - , validating splitted chunks. should easier.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -