Link to home
Start Free TrialLog in
Avatar of Rajar Ahmed
Rajar AhmedFlag for India

asked on

check currency format on keypress event

how to create textbox with following rules
   
1. Need to accept  atleast 1 or maximum  8 digits before decimal Like 12345678.00 is allowed and
   123456789.00 9 should not be allowed to enter  in onkeypress event as length exceeds 8 length
2. after decimal only two digits should be allowed
Avatar of Vishal Kedar
Vishal Kedar
Flag of India image

try below expression, it may helps

^\d{8}(\.\d{1,2})?$
You can try this regex value:

^[0-9]{1,8}([\.][0-9]{1,2})?$
Avatar of Rajar Ahmed

ASKER

hi disrupt ,
it was close
but it fails two condition
1.if 123456789-> 9 should be cleared and only 12345678 should exists
2.Decimal is not mandatory it should not accept more than 2 now error message display when i put  dot ie 1234568. this condition it fails and error msg displayed.

  function ka(keyValue) {
            var re = new RegExp("^[0-9]{1,8}([\.][0-9]{1,2})?$");
            if (!keyValue.match(re)) {
                document.getElementById("errmsg").innerHTML = 'invalid';  
            }
            else {
                document.getElementById("errmsg").innerHTML = ''; 
            }
            
        }
<input type="text" id="idTest" onkeyup="return ka(this.value)" maxlength="15"/><div id="errmsg" ></div>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of disrupt
disrupt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial