正则表达式无法正常工作 [英] regular expression not working correct

查看:87
本文介绍了正则表达式无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function validate()
{
var n=document.getElementById("name").value;
var q=document.getElementById("quantity").value;
var p=document.getElementById("price").value;
var na=/^[a-z ]*$/;
var no=/^[0-9 ]*$/;
    if (n != na)
    {
        alert("Please enter valid name.");
        return false;
    }
    if(q!=no || p!=no)
    {
        alert("Please enter valid quantity & price.");
        return false;
    }

}




为什么当我给名字"asdad"时该函数返回false并显示消息输入有效名称
请检查正则表达式是否有任何错误




why this function return false with message enter valid name when i give name "asdad"
pls check regular express if any mistake

推荐答案

/; var no =/^ [0-9] *
/; var no=/^[0-9 ]*


/; 如果(n!= na) { alert(" ); 返回 ; } 如果(q!=否|| p!= no) { alert(" ); 返回 ; } }
/; if (n != na) { alert("Please enter valid name."); return false; } if(q!=no || p!=no) { alert("Please enter valid quantity & price."); return false; } }




为什么当我给名字"asdad"时该函数返回false并显示消息输入有效名称
请检查正则表达式是否有任何错误




why this function return false with message enter valid name when i give name "asdad"
pls check regular express if any mistake


尝试此

Try this

function validate()
{
var n=document.getElementById("name").value;
var q=document.getElementById("quantity").value;
var p=document.getElementById("price").value;
var na=/^[a-z ]*


这篇关于正则表达式无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆