如果用户不遵循javascript中的验证,则文本框应保持焦点 [英] if user dont follow validation in javascript then textboxs should remain focus

查看:37
本文介绍了如果用户不遵循javascript中的验证,则文本框应保持焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是当用户破坏我的javascript验证时,他不应该被允许进一步移动,直到他纠正他的错误,但我的javascript代码允许他没有问题他没有关注我的验证。这是我的代码:

函数phval(){

var a;

a = document.getElementById(TextBox5)。value;

if(a.length!= 10)

{

alert(输入10位数);

返回false;

}

else

if(a.charCodeAt(0)== 57 &&(a.charCodeAt(1)== 56 || a.charCodeAt(1)== 55))

{

alert(有效数字);

返回true;

}

else {

alert(你的号码应该以97或98开头);

返回false;



}

}



它的工作原理是如果用户在电话号码中输入的数字少于10位现场警报,但点击确定,用户可以做所有事情。我想要的是如果用户号码开始不是97,98并且长度小于10那么他不应该被允许继续直到并且除非他纠正。我该怎么办。

what i want is when user breaks my javascript validation he should not be allowed to move further until he corrects his mistake but my javascript code is allowing him no matters he is not following my validatons . here is my code:
function phval() {
var a;
a = document.getElementById("TextBox5").value;
if (a.length != 10)
{
alert("Enter 10digit number");
return false;
}
else
if (a.charCodeAt(0) == 57 && (a.charCodeAt(1) == 56 || a.charCodeAt(1) == 55) )
{
alert("valid Number ");
return true;
}
else {
alert("Your Number Should Start with either 97 or 98");
return false;

}
}

it works in way that if user enters less than 10 digit in phone no. field alerts, but clicking ok, user is able to all things. what i want is if user number starting is not 97,98 and length is less than 10 then he should not allowed to carry on until and unless he corrects . what can i do.

推荐答案

检查给定的链接你可以看到验证手机试试这个

http://webcheatsheet.com/javascript/form_validation.php [ ^ ]
check the given link there you can see validate Phone try this
http://webcheatsheet.com/javascript/form_validation.php[^]


这篇关于如果用户不遵循javascript中的验证,则文本框应保持焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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