又一个验证号码???允许负数和期间(-.5)等 [英] Yet another validate number ??? Allow negative and period (-.5) etc.
问题描述
我不能说得对。我使用以下函数来确认用户输入
。我需要允许负数包括
带小数的那些(例如,-.5)。以下允许小数,但
不是负数。任何帮助都赞赏......一如既往。谢谢 - 凯西
函数ValidateSave(formRef,fieldName,min,max){
var formField = formRef.elements [fieldName];
if(!/ ^ \d +(\。\\\ +)?$ / .test(formField.value)){
alert(''无效的条目...请再试一次!'');
formField.focus();
formField.select();
返回false;
}
/ .test(formField.value)){
alert(''无效条目...请再试一次!'');
formField.focus();
formField.select();
返回false;
}
" KathyB" <嘉********** @ attbi.com> schreef在bericht
新闻:75 ************************* @ posting.google.co m ... < blockquote class =post_quotes>
我无法做到这一点。我使用以下函数来验证用户条目。我需要允许负数,包括带小数的那些(例如,-.5)。以下允许小数,但
不是负数。任何帮助都赞赏......一如既往。谢谢 - 凯西
你可以在没有使用isFinite函数的正则表达式的情况下执行此操作:
var num = -.5 ;
alert(isFinite(num)); //警告`true`
JW
JRS:文章< 75 ********* ****************@posting.google.com> ,在新闻中看到
:comp.lang.javascript,KathyB< Ka ********** @ attbi.com>发表于
周五,2003年12月19日16:22:53: -
我无法做到这一点。我使用以下函数来验证用户条目。我需要允许负数,包括带小数的那些(例如,-.5)。以下允许小数,但
不是负数。任何帮助都赞赏......一如既往。谢谢--Kathy
函数ValidateSave(formRef,fieldName,min,max){
var formField = formRef.elements [fieldName];
if(!/ ^ \d + (\.\d +)?
Hi,
I just can''t get this quite right. I use the following function to
validate a user entry. I need to allow negative numbers including
those with decimals (e.g., -.5). The following allows the decimals but
not the negative. Any help appreciated...as always. Thanks -- Kathy
function ValidateSave(formRef,fieldName,min,max) {
var formField = formRef.elements[fieldName];
if (!/^\d+(\.\d+)?$/.test(formField.value)) {
alert(''Invalid entry...please try again!'');
formField.focus();
formField.select();
return false;
}解决方案/.test(formField.value)) {
alert(''Invalid entry...please try again!'');
formField.focus();
formField.select();
return false;
}
"KathyB" <Ka**********@attbi.com> schreef in bericht
news:75*************************@posting.google.co m...Hi,
I just can''t get this quite right. I use the following function to
validate a user entry. I need to allow negative numbers including
those with decimals (e.g., -.5). The following allows the decimals but
not the negative. Any help appreciated...as always. Thanks -- Kathy
You cand do this without regular expressions with the isFinite function:
var num = -.5;
alert(isFinite(num)); // Alerts `true`
JW
JRS: In article <75*************************@posting.google.com> , seen
in news:comp.lang.javascript, KathyB <Ka**********@attbi.com> posted at
Fri, 19 Dec 2003 16:22:53 :-
I just can''t get this quite right. I use the following function to
validate a user entry. I need to allow negative numbers including
those with decimals (e.g., -.5). The following allows the decimals but
not the negative. Any help appreciated...as always. Thanks -- Kathy
function ValidateSave(formRef,fieldName,min,max) {
var formField = formRef.elements[fieldName];
if (!/^\d+(\.\d+)?
这篇关于又一个验证号码???允许负数和期间(-.5)等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!