且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用于 Javascript 的 RegEx 仅允许字母数字

更新时间:2023-02-20 08:19:49

/^[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

更新(支持通用字符)

如果您需要此正则表达式支持通用字符,您可以在此处找到Unicode 字符列表.

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

例如:/^([a-zA-Z0-9u0600-u06FFu0660-u0669u06F0-u06F9 _.-]+)$/

这将支持波斯语.