RegEx for Javascript to allow only alphanumeric

前端 未结 18 1505
轻奢々
轻奢々 2020-11-22 15:13

I need to find a reg ex that only allows alphanumeric. So far, everyone I try only works if the string is alphanumeric, meaning contains both a letter and a number. I just w

18条回答
  •  礼貌的吻别
    2020-11-22 15:29

    /^[a-z0-9]+$/i
    
    ^         Start of string
    [a-z0-9]  a or b or c or ... z or 0 or 1 or ... 9
    +         one or more times (change to * to allow empty string)
    $         end of string    
    /i        case-insensitive
    

    Update (supporting universal characters)

    if you need to this regexp supports universal character you can find list of unicode characters here.

    for example: /^([a-zA-Z0-9\u0600-\u06FF\u0660-\u0669\u06F0-\u06F9 _.-]+)$/

    this will support persian.

提交回复
热议问题