I want to create JavaScript Regex for checking value of textbox in range (U+06F0 to U+06F9) or (0-9)
How can I build this?
Put the range inside a character class like below.
^[\u06F0-\u06F90-9]+$
+ repeats the previous token one or more times.
You can test the regex pattern on regexr.com and then use it in your code. I use to match the Persian mobile number with Unicode in blew:
<\u06F0 to \u06F9> equal to <۰-۹> that matches Persian number like this: ۰۹۱۹۹۱۹۱۱۲۲.
    $("#registerForm").validate({
        rules:{
            mobile:{
                required:true,
                pattern : ^[\u06F0][\u06F0-\u06F9]{3}[\u06F0-\u06F9]{3}[\u06F0-\u06F9]{4},
            },
        },
        messages:{
            mobile:{
                required:"شماره تلفن همراه خود را وارد کنید",
                number:"فقط عدد وارد کنید",
                pattern:"تلفن همراه را به درستی وارد کنید"
            },
        },
        errorClass: "help-inline",
        errorElement: "span",
    });
                        I suggest this pattern based on my searches:
pattern = "^([\u06F0]|[0])([\u06F9]|[9])(([\u06F0-\u06F9]|[0-9]){2})(([\u06F0-\u06F9]|[0-9]){3})(([\u06F0-\u06F9]|[0-9]){4})"
It's a little complicated, but works if you want to input both Persian and English numbers in Persian phone number format. I've just used | as or, parentheses for grouping. As @ahmad_mhm mentioned, you can test it on RegExr.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With