本文介绍了检查文本字段是否在javascript中包含字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Java语言的新手,我想知道是否有一种方法可以检查文本字段输入中是否包含数字以外的内容。
I am new at Javascript and I wanted to know if there is a way to check if textfield input contains anything other than numbers.
我知道该怎么做
推荐答案
是的-只是字符串上的标准正则表达式:
Yup - just standard regex on the string:
var str = 'mystring 123';
if(str.match(/[^0-9]/)) { ... }
如果您需要知道如何从元素中获取字符串:
If you need to know how to get the string from the element:
var str = document.getElementById('myId').value;
这篇关于检查文本字段是否在javascript中包含字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!