使用javascipt对文本框值进行数据类型验证? [英] Data type validation for textbox value using javascipt?
本文介绍了使用javascipt对文本框值进行数据类型验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用javascipt验证文本框值的数据类型?例如验证输入的数据是否为decimal / int。
我目前正通过if else方法进行验证。
我尝试过的方法:
if(...)
{
}
else(... )
{
}
How can I validate the datatype of the textbox value using javascipt? e.g. validate if data entered is decimal/int.
I'm currently validating through the if else methods.
What I have tried:
if (...)
{
}
else(...)
{
}
推荐答案
var value = document.getElementById('textboxID').value;
if (isNaN(value))
alert('not an number')
else
alert('valid number');
参考 JavaScript isNaN()函数 [ ^ ]
这篇关于使用javascipt对文本框值进行数据类型验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文