Regular Expression not to allow numbers - just Arabic letters

前端 未结 4 1606
猫巷女王i
猫巷女王i 2021-01-30 18:43

I found this regular expression for Arabic letters but it is also allowing numbers with letters. How can I change it to let it allow letters only ?

/[\\u0600-\\u         


        
相关标签:
4条回答
  • 2021-01-30 19:08

    Probably you'd have to check what range the numbers match and exclude it (formally not include in brackets expression).

    Here I've found another helpful source.

    I'd suggest this for only letters

    /[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]/
    

    as this matches arabic digits only

    /[\u0660-\u0669\u06F0-\u06F9]/
    

    Edit:

    I've found that there are two ranges for arabic and arabic-indic digits in unicode.

    If you need a regex to match a line just then, when it contains arabic letters and numbers - use this:

    /^[\u0600-\u06FF]*$/
    

    If you want to also discourage arabic digits - use this:

    /^[\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]*$/
    

    If you want to match a substring, not only a whole line, use this:

    /\b[\s\u0600-\u065F\u066A-\u06EF\u06FA-\u06FF]*\b/
    
    0 讨论(0)
  • 2021-01-30 19:18
    [RegularExpression(@"^[\u0621-\u064A\u0660-\u0669a-zA-Z]+$", ErrorMessage = "You can enter Arabic or English characters only")] 
    
    [RegularExpression(@"^[0-9]+$", ErrorMessage = "You can enter numbers only")]
    
    [RegularExpression(@"^[a-zA-Z\0-9]+$",ErrorMessage = "You can enter numbers or english characters only")]
    
    [RegularExpression(@"^[\u0621-\u064A\u0660-\u0669\0-9]+$", ErrorMessage = "You can enter numbers or arabic characters only")]
    
    [RegularExpression(@"^[\u0621-\u064A\u0660-\u0669]+$", ErrorMessage = "You can enter arabic characters only")]
    
    [RegularExpression(@"^[a-zA-Z]+$",ErrorMessage = "You can enter english characters only")]
    
    0 讨论(0)
  • 2021-01-30 19:19

    First, concerning Arabic encoding in unicode, you might want to refer to this tables here

    As for the regex you were given, [\u0600-\u06FF] is the range of all arabic characters on the unicode listing, definitely that includes even letters, control characters, white-space, and numbers.

    My recommendation would be:

    /[\u0600-\u06FF&&[^\U06F0-\06F9]]/
    

    Which spans just everything minus the arabic numeric digits (0-9).

    That subtracts a range from the 'super' range. Am just not sure whether your target regex dialect supports this.

    0 讨论(0)
  • 2021-01-30 19:22

    I tried all solutions provided here, nothing worked, finally one solution worked for me for Arabic letters only

    ^[\u0621-\u064A\040]+$
    
    0 讨论(0)
提交回复
热议问题