RegExp

E

Enzo

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
 
E

Evertjan.

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?
 
E

Enzo

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
 
E

Evertjan.

Enzo wrote on 30 aug 2005 in comp.lang.javascript:
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.

myTestValue = 1.1234

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

alert( re.test(myTestValue) )
 
A

Alvaro G Vicario

*** 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;');
 
E

Evertjan.

Alvaro G Vicario wrote on 30 aug 2005 in comp.lang.javascript:
*** Enzo wrote/escribió (Tue, 30 Aug 2005 11:17:10 GMT):

You can take this a start point:

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

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

Evertjan.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top