Regular expression for indian car number in javascript and php

I need regex in Javascript as well as in PHP for the NUMBER Indian car.

Here is a list of conditions:

(x)(y)(z)(m)(a)(b)(c)

1. (x) contains only alphabets of length 2.
2. (y) can be -either a single space ' '.
3. (z) contains only numbers of length 2.
4. (m) can be either ,or single space ' '.
5. (a) there must be one or two alphanumeric characters followed by alpha.
6. (b) must be identical to (y).
7. (c) contains only numbers of length 4.

Here are some examples of valid car numbers:

  • RJ-14, NL-1234
  • RJ-01,4M-5874
  • RJ-07,14M-2345
  • RJ 07,3M 2345
  • RJ-07,3M-8888
  • RJ 07 4M 2345
  • RJ 07,4M 2933

( ):

  • RJ-07 3M 1234 ( (y) (b) ).
  • RJ-07 M3-1234 ((a) ).
  • rj-07 3M-123 ( (c) 4).
+3
3

... / langauges:

([a-z]{2}-\d{2}[ ,][a-z0-9]{1,2}[a-z]-\d{4})|([a-z]{2} \d{2}[ ,][a-z0-9]{1,2}[a-z] \d{4})

, "" , , , " (y) (b) ".

+1

, . , 5, , :

^[A-Z]{2}[ \-][0-9]{2}[ ,][A-Z0-9]{2,3}[ \-][0-9]{4}$

7 8 ( 9, 14, 13) 5. , , 3 7 .

, , , ( ), , .


5 6., , . 5 , , , .

6 , , , .

, :

^[A-Z]{2}([ \-])[0-9]{2}[ ,][A-Z0-9]{1,2}[A-Z]\1[0-9]{4}$

(, ), , .

+1

Try:

<?php
$arr = array("RJ-14,NL-1234", "RJ-01,4M-5874", "RJ-07,14M-2345", "RJ 07,3M 2345", "RJ-07,3M-8888", "RJ 07 4M 2345", "RJ 07,4M 2933","RJ-07 3M 1234","RJ-07 M3-1234","rj-07 M3-123");

foreach($arr as $str) {
    if(preg_match('/[a-z]{2}( |-)\d{2}(?: |,)(?:[a-z\d]{1,2}[a-z])\1\d{4}/i',$str))
        print "$str\tYES\n";
    else
        print "$str\tNO\n";
}

?>

Conclusion:

RJ-14,NL-1234   YES
RJ-01,4M-5874   YES
RJ-07,14M-2345  YES
RJ 07,3M 2345   YES
RJ-07,3M-8888   YES
RJ 07 4M 2345   YES
RJ 07,4M 2933   YES
RJ-07 3M 1234   NO
RJ-07 M3-1234   NO
rj-07 M3-123    NO
0
source

Source: https://habr.com/ru/post/1736647/


All Articles