jsp 正则表达式,我想把代码写成如果不为空就验证邮箱格式是否正确
function valiEmail(emailObj){
emailObj.className='';
var spanObj = document.getElementById('email_msg');
spanObj.innerHTML='';
var reg = /^[a-zA-Z0-9]{5,15}@[a-zA-Z0-9]{2,10}[.](com|net)$/;
if(!reg.test(emailObj.value)){
spanObj.innerHTML='email格式不正确';
emailObj.className='s2';
return false;
}
return true;
}
答案:function valiEmail(emailObj){
emailObj.className='';
var spanObj = document.getElementById('email_msg');
spanObj.innerHTML='';
var reg = /^[a-zA-Z0-9]{5,15}@[a-zA-Z0-9]{2,10}[.](com|net)$/;
emailObj.value=emailObj.value.replace(/(^\s*)|(\s*$)/g, "");
if(emailObj.value.length == 0)
{
spanObj.innerHTML='请输入email';
emailObj.className='s2';
return false;
}
if(!reg.test(emailObj.value)){
spanObj.innerHTML='email格式不正确';
emailObj.className='s2';
return false;
}
return true;
}
上一个:JSP,购物车生成订单,急求代码!!
下一个:JSP购物车代码详解