0

I'm trying to match the following format:

T123ABC

When people insert they could do it with spaces or dashes. I am trying to use this format for jquery validator but for some reason it is not working:

$.validator.addMethod('numberplateTZ', function (value) { 
    var reg = value.replace(" ","");
    reg = reg.replace("-","");
    return /[a-z]{1}[0-9]{3}[a-z]{3}$/.test(reg); 
}, 'Numberplate format: T XXX ABC...');
2
  • 1
    replace() with string, replaces a single occurrence, to replace all occurrences use replace(/\s+/g, ''). Missing anchor ^ in regex. Use i flag for case-insensitive match. Commented Feb 5, 2016 at 8:57
  • Sounds like an answer Commented Feb 5, 2016 at 10:15

1 Answer 1

1

Here is the Working Fiddle

replace the regex as below

return /[A-Za-z]{1}[0-9]{3}[A-Z]{3}$/.test(reg); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.