JavaScript: \\d{4} RegExp allows more than 4 digits [duplicate]
问题 This question already has answers here : Match whole string (3 answers) Closed last year . Have following validation for year value from text input: if (!year.match(new RegExp('\\d{4}'))){ ... } RegExp equals null if numeric of digits from 0 to 3. It's OK. In case 4 digits it returns value. It's OK. In case more than 4 digits it returns value again,that it's NOT OK . Documentation says {n} declaration means exact number,but works like: exact+ With such ugly validation it work's fine: if (