如何使正则表达式符合规则
username.com x
username.comme o这是我的,如果包含点,下划线,破折号,
以及如何排除扩展字符串。
^[a-zA-Z0-9_.-]*\w{5,}$
发布于 2016-03-17 00:03:00
会是这样的:
^([\w.-](?!\.(com|net|html?|js|jpe?g|png)$)){5,}$解释:
^ # from start
([\w.-] # \w is equal to [a-zA-Z0-9_]
(?!\. # in front can NOT be a dot followed by
(com # com
|net # OR net
|html? # OR htm or html # ? means optional match
|js # OR js
|jpe?g # OR jpg or jpeg
|png # OR png
)$ # block only if it is at the end
) # end of the negative lookahead
){5,} # match at least 5 characters in above conditions
$ # till the end希望能帮上忙。
发布于 2016-03-17 00:06:00
虽然你可以(可能)把它变成一个regexp,但是它的表现会非常糟糕.如果使用一个可以使用两个正则表达式的函数,情况会好得多。
第二部分可能会更好地进行数组检查,将所有的值分割成一个数组。
function isValid(str) {
return (/^([\w\d_\.]{5,})$/i).test(str)
&& !(/\.(dll|com|net|exe|php|html|js|jpeg|jpg|png|tiff|gif)$/i).test(str);
}https://stackoverflow.com/questions/36049205
复制相似问题