美文网首页
URL网址校验

URL网址校验

作者: 小仙有毒_1991 | 来源:发表于2020-05-12 11:59 被阅读0次

第一种

/^(file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp):\/\/([a-zA-Z0-9_-]+[\.])*([a-zA-Z0-9_-]+(:([0-9]{1,4}|[0-5][0-9]{1,4}|6[0-4][0-9]{1,3}|65[0-4][0-9]{1,2}|655[0-2][0-9]|6553[0-5]))?(\/[a-zA-Z0-9_-]+)*([\.][a-zA-Z0-9]+)?)[\/]?([?][a-zA-Z0-9-_]+[=][a-zA-Z0-9-_]*([&][a-zA-Z0-9-_]+[=][a-zA-Z0-9-_]*)*)?$/

第二种

^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$

你们觉得哪种好呢?

相关文章

网友评论

      本文标题:URL网址校验

      本文链接:https://www.haomeiwen.com/subject/pzqbnhtx.html