我需要验证域名网址,在某些情况下我的编码工作正常,但并非在所有情况下。
并且验证表达式为^(http|https)://[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$
对于上面的例子,我必须允许URL,但它显示无效的URL。
答案 0 :(得分:0)
您需要在字符类之外转义句点(。):
^(http|https)://[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}$
答案 1 :(得分:0)
试试这个
/^((https?:\u005c/\u005c/))(([A-Z0-9_~%!$&\u0027()*+,;=\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef-]+(\u005c.[A-Z0-9_~%!$&\u0027()*+,;=\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef-]+)*)\u005c.(aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|no|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|uk|gd|ge|gf|fr|gg|gh|gi|gl|gm|gn|gp|fr|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mn|mo|mp|mq|fr|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|fr|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|fr|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|fr|ro|rs|yu|ru|su|rw|sa|sb|sc|sd|se|sg|sh|si|sj|no|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|fr|tg|th|tj|tk|tl|tp|tm|tn|to|tp|tl|tr|tt|tv|tw|tz|ua|ug|uk|us|gov|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|fr|ws|ye|yt|fr|yu|za|zm|zw|arpa|[0-9_~%!$&\u0027()*+,;=\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef-]+)|[0-9]{1,3}(\u005c.[0-9]{1,3}){3})([:\u005c/?]|$)/i','adSecurityMap.0':'Non-Secure','adSecurityMap.602476':'Secure','featureShowPlacementCountOnAdLibraryAvailable':'true','yahooOO':'false','fileExtensionToMaxSizeJSONMap':'{\u0022swf\u0022:\u0022102400\u0022,\u0022gif\u0022:\u0022102400\u0022,\u0022png\u0022:\u0022102400\u0022,\u0022jpeg\u0022:\u0022102400\u0022,\u0022jpg\u0022:\u0022102400\u0022,\u0022mov\u0022:\u0022786432000\u0022,\u0022wmv\u0022:\u0022786432000\u0022,\u0022avi\u0022:\u0022786432000\u0022,\u0022mpg\u0022:\u0022786432000\u0022,\u0022mp4\u0022:\u0022786432000\u0022,\u0022flv\u0022:\u0022786432000\u0022,\u0022webm\u0022:\u0022786432000\u0022,\u0022zip\u0022:\u002210485760\u0022}
答案 2 :(得分:0)
在JS中:
if('http://www.abc.com'.search(/^https?:\/\/([a-z0-9]+\.)+[a-z]{2,5}$/) != -1)