Re: beginner: regex how to check that value is only numbers
- From: Dr John Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Jan 2006 17:51:40 +0000
JRS: In article <Iq-dnTDq4vi8nEveRVn-hA@xxxxxxxxxxx>, dated Tue, 24 Jan
2006 05:28:01 remote, seen in news:comp.lang.javascript, Randy Webb
<HikksNotAtHome@xxxxxxx> posted :
>nescio said the following on 1/24/2006 4:35 AM:
>> i must check if the value of a text field is a number (they have to fill in
>> a number between 7 and 10 digits),
>> so: 1234567 is allowed
>> and 123456789999 is not allowed;
>
>function checkNumber(numToCheck){
>if(parseInt(numToCheck,10)==numToCheck&&(numToCheck.length>7)&&numToCheck.length<10)
>{alert('valid')}
>else
>{alert('invalid')}
>}
No. It accepts "123456e0" and "0x000000" and "+1234567"; the first
is a value outside the possibly-intended range, and the user asks for
all-digit input.
Also, you've taken "between" to mean "between", which is not what the
ignorant generally intend.
The OP may well not want "0000000" or "0004567" so the RegExp way should
probably be like
OK = /^[1-9]\d{6,9}$/.test(Meadow)
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.
- Follow-Ups:
- Re: beginner: regex how to check that value is only numbers
- From: Randy Webb
- Re: beginner: regex how to check that value is only numbers
- References:
- beginner: regex how to check that value is only numbers
- From: nescio
- Re: beginner: regex how to check that value is only numbers
- From: Randy Webb
- beginner: regex how to check that value is only numbers
- Prev by Date: Re: Simple Calculation in Form - 3 textboxes - 1 function
- Next by Date: Re: Gathering data from form fields within iFrames
- Previous by thread: Re: beginner: regex how to check that value is only numbers
- Next by thread: Re: beginner: regex how to check that value is only numbers
- Index(es):
Relevant Pages
|