javascript正则表达式验证(如果没有内容)
我对表单字段进行了以下验证:javascript正则表达式验证(如果没有内容),javascript,regex,Javascript,Regex,我对表单字段进行了以下验证: $(".controlsphone input").blur(function() { var ree = /^\d+$/; if(ree.test(document.getElementById("register_telephone").value)) { $(this).css('border-color','green'); $(this).siblings('.info').c
$(".controlsphone input").blur(function() {
var ree = /^\d+$/;
if(ree.test(document.getElementById("register_telephone").value))
{
$(this).css('border-color','green');
$(this).siblings('.info').css('display','none');
$(this).siblings('.error').css('display','none');
$(this).siblings('.valid').css('display','inline-block');
$("#email_error401112").hide();
$('#registerErrors').hide();
}
else
{
$('#registerErrors').show();
$('#email_error401112').remove();
$('#registerErrors').append('<p id="email_error401112">Please enter a phone number</p>');
}
});
$(“.controlsphone输入”).blur(函数(){
变量ree=/^\d+$/;
if(ree.测试(document.getElementById(“寄存器”)值))
{
$(this.css('border-color','green');
$(this.sides('.info').css('display','none');
$(this).sides('.error').css('display','none');
$(this).sides('.valid').css('display','inline-block');
$(“#电子邮件\u error401112”).hide();
$(“#注册表错误”).hide();
}
其他的
{
$(“#注册表错误”).show();
$('#email_error401112')。删除();
$(“#registerErrors”)。追加(“请输入电话号码”
”;
}
});
我只想在数字存在时验证该字段。字段不是必需的,但如果字段中有内容,则需要有效(数字)
上面的代码看起来怎么样?我能做些什么来实现这一点
干杯,丹
var ree = /^\d*$/;
因为+
代表一个或多个,不包括零
如果目标浏览器: