Regex for persian number

后端 未结 2 1293
旧巷少年郎
旧巷少年郎 2020-12-11 20:10

I want to create javascript Regex for checking value of textbox in range \"U+06F0 and U+06F9\" or \"0-9\" How can I build this?

相关标签:
2条回答
  • 2020-12-11 20:34

    Put the range inside a character class like below.

    ^[\u06F0-\u06F90-9]+$
    

    + repeats the previous token one or more times.

    0 讨论(0)
  • 2020-12-11 20:51

    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",
    
        });
    
    0 讨论(0)
提交回复
热议问题