Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / August 2005



Tip: Looking for answers? Try searching our database.

RegExp

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Enzo - 30 Aug 2005 12:17 GMT
Hi,

I need to create a dynamically pattern match
for validate a number input, first without
decimals and then with 2 or more decimals.

Thanks in advance,

Enzo
Evertjan. - 30 Aug 2005 12:29 GMT
Enzo wrote on 30 aug 2005 in comp.lang.javascript:

> I need to create a dynamically pattern match
> for validate a number input, first without
> decimals and then with 2 or more decimals.

What do you mean by "dynamically"?

What did you try yourself?

Signature

Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Enzo - 30 Aug 2005 13:05 GMT
Hi Evertjan,

I tried this pattern:

/^-?\d+(\.\d{1,3})?$/

for 1 to 3 decimals, but I need to replace
the static values '1' & '3' with variables.

Thanks again,

Enzo
Evertjan. - 30 Aug 2005 14:27 GMT
Enzo wrote on 30 aug 2005 in comp.lang.javascript:

> Hi Evertjan,
>
[quoted text clipped - 4 lines]
> for 1 to 3 decimals, but I need to replace
> the static values '1' & '3' with variables.

myTestValue = 1.1234

a = 1
b = 3
myRegex = "^-?\\d+\\.\\d{"+a+","+b+"}?$"
re = new RegExp(myRegex,"");

alert( re.test(myTestValue) )

Signature

Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Enzo - 30 Aug 2005 16:04 GMT
Works great! Thanks Evertjan!

Enzo
Dr John Stockton - 31 Aug 2005 12:42 GMT
JRS:  In article <1YXQe.3343174$I96.3853437@telenews.teleline.es>, dated
Tue, 30 Aug 2005 12:05:17, seen in news:comp.lang.javascript, Enzo
<yuyu@yuyu.com> posted :

>I tried this pattern:
>
>/^-?\d+(\.\d{1,3})?$/
>
>for 1 to 3 decimals, but I need to replace
>the static values '1' & '3' with variables.

Unless this is school work, you do not *need* to replace the values,
since you can also use (\.\d+) and test the length of the match.

<URL:http://www.merlyn.demon.co.uk/js-valid.htm>

Signature

© 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.

Alvaro G Vicario - 30 Aug 2005 14:29 GMT
*** Enzo wrote/escribió (Tue, 30 Aug 2005 11:17:10 GMT):
> I need to create a dynamically pattern match
> for validate a number input, first without
> decimals and then with 2 or more decimals.

You can take this a start point:

    var my_filter=new Array('foo', 'bar');
    eval('var re_filter=/^(' + my_filter.join('|') + ')$/i;');

Signature

-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--

Evertjan. - 30 Aug 2005 15:08 GMT
Alvaro G Vicario wrote on 30 aug 2005 in comp.lang.javascript:

> *** Enzo wrote/escribió (Tue, 30 Aug 2005 11:17:10 GMT):
>> I need to create a dynamically pattern match
[quoted text clipped - 5 lines]
>      var my_filter=new Array('foo', 'bar');
>      eval('var re_filter=/^(' + my_filter.join('|') + ')$/i;');

Never use eval(),
it is evil and not necessary.

Signature

Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Enzo - 30 Aug 2005 15:58 GMT
Gracias Alvaro,

pero como dice Evertjan, eval is 'evil' ;-)

Saludos,

Enzo
Evertjan. - 30 Aug 2005 16:13 GMT
Enzo wrote on 30 aug 2005 in comp.lang.javascript:

> pero como dice Evertjan, eval is 'evil' ;-)

Because it is true and has been explained so many times in this NG.

Please see the archive.

Signature

Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.