通过正则表达式进行 javaScript 文本验证

javaScript text validation by regex

本文关键字:javaScript 文本 验证 正则表达式      更新时间:2023-09-26

我需要检查 java 脚本中的字符串是否以 http:// 开头

我拥有的是

if(!txt.match(/^http:/)) {}  // this only works for http:

我需要让它为http://工作

任何人都可以提出解决方案吗?

或者:

txt.substr(0, 7) === "http://"
您需要转

'字符,也为了检查最好使用test方法。

if(!(/^http:'/'//.test(txt))) {}