一个验证的问题,请教高手
有一段字符串 asdadadad0510-54013882asdadsasdsdljflakdjsflajd;lskjfla;kdsfssss@163.comlskdjfljaldsjf
我有什么办法可以判断这段字符串中是否有0510-54013882这中电话格式和ssss@163.com这种email格式的字符存在?
------解决方案-------------------- <script language=javascript>
str= "asdadadad0510-54013882asdadsasdsdljflakdjsflajd;lskjfla;kdsfssss@163.comlskdjfljaldsjf "
var re=/(\d{4}-\d{8})/ig;
var re2=/\w+@\w+\.\w+?/ig;
if(re.test(str))
alert( "ok ");
else
alert( "no ");
if(re2.test(str))
alert( "ok ");
else
alert( "no ");
</script>
简单判断