Javacript验证问题 [英] Javacript Validation Problem
本文介绍了Javacript验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Guys
你能帮助我们如何进行javascript验证吗?我想在用户同时输入数字和非数字值时提醒消息文本字段。例如min234。
如果将上述示例插入到文本字段中,则应显示弹出消息,例如请仅输入非数字值。我已经尝试过该代码,但它不起作用:
Hello Guys
Can you please help how to make javascript validation?I want to alert a message when a user input both a numeric and a non numeric value in a textfield. e.g. min234.
If the above example was inserted into a textfield a pop up message should be displayed such as "Please enter a non-numeric value only". I've already try that code but it does not work:
function validateFN()
{
var x=document.forms["form1"]["firstname"].value;
if ( isNaN (x) )
{
alert("Numbers cannot be inserted!");
return false;
}
}
谢谢你帮助
Thanks guy please help
推荐答案
你可以添加一个如果你的代码声明更多,如下所示:
x = document.myForm.myInput.value;
You could add one more else if statement to your code like below:
x=document.myForm.myInput.value;
else if(isNaN(x))
{
alert("Number cant be alphabet")
return false
}
以下是完整的脚本
Below is the Full Script
<script>
function validate(){
x=document.myForm.myInput.value;
if (x >=10)
{
alert("Number is bigger than 10")
return true
}
else if(isNaN(x))
{
alert("Number cant be alphabet")
return false
}
else
{
alert("Number is smaller than 10")
return false
}
}
</script>
如果您需要,可以访问这个 [ ^ ]和这个 [ ^ ] links。
Further in details if you required you can visit This[^] and This[^] links.
这篇关于Javacript验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文