1

I have a web application related vehicle record, in this application I want to add vehicle number. but client want fix format like box for it ->

RJ 19 NP 5020 

please anybody help me for it. thanks!

2
  • Did you try anything Commented Sep 6, 2016 at 7:51
  • A regex is OK . Try writing . Commented Sep 6, 2016 at 7:52

3 Answers 3

1

Try this regex

 ^[A-Z]{2}[ -][0-9]{1,2}(?: [A-Z])?(?: [A-Z]*)? [0-9]{4}$ 
Sign up to request clarification or add additional context in comments.

7 Comments

hello Nikhil sir, can you give detail, how to use this ?
you can write RJ 19 NP 5020 as RJ-19,NP-5020
sir can I set it in html input field like " RJ-19-NP-5020 " this format
yes just change above regex to ^[A-Z]{2}[ \-][0-9]{2}[ -][A-Z0-9]{2,3}[ \-][0-9]{4}$
|
1

Use html pattern with regex like so:

<input type="text" pattern="^([A-HJ-PR-Y]{2,2}[056][0-9]\s?[A-HJ-PR-Y]{3,3})$|^([A-HJ-NP-Y]{1,3}[0-9]{2,3}?\s[A-Z]{3,3})$|^([A-Z]{1,3}\s?[0-9]{1,4}([A-Z]{1,1})?)$|^([0-9]{4,4}[A-Z]{1,3})$|^([A-Z]{1,2}\s?[0-9]{1,4})$|^([A-Z]{2,3}\s?[0-9]{1,4})$|^([0-9]{1,4}\s?[A-Z]{2,3})$"> 

I found this regex googling for UK number plate regex, and it seems to work OK for all the number plates (UK) i know.

see my fiddle for a test: https://jsfiddle.net/7yh2wo12/3/

Comments

0

You can use pattern HTML5 attribute where you can define regex for your string

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.