Search code examples
regexentity-frameworkmodel-view-controllerasp.net-mvc-5nsregularexpression

MVC 5 Entity Regular Expression for Arabic number is not working?


my regular expression is like,

//    [RegularExpression("^[0-9]*$", ErrorMessage = "must be numeric")]
    [RegularExpression("^[\u0660-\u0669]{10}$", ErrorMessage = "must be numeric")]
    public Nullable<int> DecisionNumber { get; set; }

I am using one Regular expression at a time when i use first one [0-9] it works fine and only allow me to type english number 123... etc

But in second expression it allow me to type english number not arabic number. On english number it gives error must be number

How can i write expression for arabic number up to 10 digits.

Hopes for your reply


Solution

  • Try this

    [RegularExpression("^[\u0660-\u0669]{1,10}$", ErrorMessage = "must be numeric")]
    public string DecisionNumber { get; set; }
    

    The ^[\u0660-\u0669]{1,10}$ regex will match 1 to 10 Arabic digits. The DecisionNumber should be of type string.