PDA

View Full Version : Allow width in percentages and pixels only



guvenck
Sep 12th, 2007, 02:33 PM
Hello,

I have a form field where I let the user enter desired width for a table. The field should allow values in percentage or in pixels only. A JS check should allow the user to enter valid values like '80%' or '760' only. Other illegal values like '%80', 'blah' or '90px' should not be allowed.

How can I do this?

Arty Effem
Sep 12th, 2007, 03:23 PM
Hello,

I have a form field where I let the user enter desired width for a table. The field should allow values in percentage or in pixels only. A JS check should allow the user to enter valid values like '80%' or '760' only. Other illegal values like '%80', 'blah' or '90px' should not be allowed.

How can I do this?

Perhaps:
if( !/^\d+%?$/.test(formField.value.replace(/\s+/g,'')) )
alert("Enter n[n][%] only")