检查字符串是否包含任何数字 [英] check if string contains any numbers
问题描述
我需要一个可以查看字符串的支票,看它是否包含任何
数字。
请帮助!
i need a check that can go through a string to see if it contains any
numbers.
Please help!
推荐答案
Mokka写道:
我需要一个检查,可以通过一个字符串来查看它是否包含任何
数字。
i need a check that can go through a string to see if it contains any
numbers.
函数hasNumbers(t)
{
返回/\d/.test(t );
}
如果t包含数字则返回true,否则返回false。
-
Rob
function hasNumbers(t)
{
return /\d/.test(t);
}
Returns true if t contains numbers, otherwise false.
--
Rob
RobG写道:
Mokka写道:
Mokka wrote:
我需要一个可以查看字符串的检查看它是否包含任何
数字。
i need a check that can go through a string to see if it contains any
numbers.
函数hasNumbers(t)
{
返回/\d/.test(t);
}
如果t包含数字,则返回true,否则返回false。
function hasNumbers(t)
{
return /\d/.test(t);
}
Returns true if t contains numbers, otherwise false.
如果t包含在l,则应该返回true east one
number,否则为false。
因此该函数应该被称为hasNumber()或hasDigit()。
-
Rob
That should probably be returns true if t contains at least one
number, otherwise false.
So the function should probably be called hasNumber() or hasDigit().
--
Rob
说,myVar是你的对象检查,如果(/\d/.test(myVar)).....
Danny
Say, myVar is your object to be checked, if (/\d/.test(myVar)) .....
Danny
这篇关于检查字符串是否包含任何数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!