Bilal Shaikh
Bilal Shaikh

Reputation: 115

RegEx for Matching Saudia (KSA) Vehicle Number Patterns

Can someone help me with regex for saudia(KSA) Vehicle registration plates Basically i'm unable to write regex for latin as it only accept 17 Arabic letters as following with their following english translation

ا |  A  
ب |  B  
ح |  J  
د |  D  
ر |  R  
س |  S  
ص |  X  
ط |  T  
ع |  E  
ق |  G  
ك |  K  
ل |  L  
م |  Z  
ن |  N  
هـ |     H  
و |  U  
ى |  V 

as user can enter in both english and arabic i don't know how to restrict latin character while i can restrict english alphabets with regex

Saudia(KSA) car number pattern contail three letters and up to four numbers

This is the sample car license number plate

Upvotes: 2

Views: 1186

Answers (3)

Logan Bertram
Logan Bertram

Reputation: 1942

If you're looking for what I think you're looking for, this will accept up to 4 numbers, but no mix of both types of characters within the number or character blocks (although a user can do Arabic numbers and Saudi characters or Saudi numbers and Latin characters).

^[\u0660-\u0669|\d]{1,4}[\u0621-\u064A|\w]{3}

Legal entries:

٢٤٧٩sdf
1334aif
1234حكهـ
حكهـ٢٤٧٩
123abc
12abc
1abc

Illegal Entries:

٢1٧2 sكf
alfksjdd
12347844

Note that the end of line symbol ($) is omitted as this conflicts with Arabic's directionality. The beginning of line symbol is fine and is necessary to prevent longer, illegal entries which contain the pattern.

Upvotes: 4

Nikita Kurtin
Nikita Kurtin

Reputation: 6237

According to given image example and

Saudia(KSA) car number pattern contain three letters and up to four numbers

You could do it simply, like this:

\d{1,4}[A-Z]{3}

Explanation:

\d{1,4} -> means between 1 and 4 digits

[A-Z]{3} -> means 3 upper case letters

But if you need to include arabic letters as well, then you should use their unicode specific code points, which you can find here Unicode for Arabic letters.

Unfortunately I don't know arabic, so I can't test it more than just copy-pasting some of letters you gave.

But theoretically it would be something like this:

\d{1,4}[A-Z\x{0600}-\x{06FF}]{3}

Explanation:

\d{1,4} -> means between 1 and 4 digits

[A-Z\x{0600}-\x{06FF}]{3} -> means 3 unicode characters with code between 0600 and 06FF (according to attached table)

Upvotes: 1

vasile_t
vasile_t

Reputation: 390

Here is an example that restricts you to the letters A, B and C. You can replace with the specific list of letters:

\d{4}[ABCD]{3}

Upvotes: -3

Related Questions