java-json-tools / json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order
http://json-schema-validator.herokuapp.com/
Other
1.63k stars 399 forks source link

Validation Error : [0-9]{3}-[0-9]{3}-[0-9]{4} is not working #203

Open arghyabanerjee opened 8 years ago

arghyabanerjee commented 8 years ago

For this regex [0-9]{3}-[0-9]{3}-[0-9]{4} format not reporting any validation exception for this format

2222-333-55555

The issue is first(2222) and last(55555) part if length is more than 3 and 4 character it's not showing any validation exception. If length is less than 3 and 4 character it's showing validation exception.

Accepting characters, Not showing any validation exception for this value 22235abcd345641-111-11199

nwolff commented 8 years ago

Hi, I'm doing the same kind of validations and the library works well. Right now the regex you defined will succeed when it finds the pattern anywhere in the string, to match the full string you need to add start of line / end of line anchors like this:

^[0-9]{3}-[0-9]{3}-[0-9]{4}$

This is also explained in the documentation: https://github.com/daveclayton/json-schema-validator/wiki/Status#regex-support-ecma-262-and-the-real-definition-of-matching