Link to home
Start Free TrialLog in
Avatar of Jazzy 1012
Jazzy 1012

asked on

Javascript not to let an input enter more or less

Javascript to accept 16 characters(all numbers), not less or not more
<div class="col-xs-4">
<div style="text-align:left;" class="form-group">
<label for="credit0_number">Credit Card Number</label>
<input type="number" class="inp form-control" id="credit0_number" name="credit0[number]" >
</div>
 </div>

Open in new window

Avatar of Bill Prew
Bill Prew

You can use a regular expression to verify this in your form edits routine.  The basic idea is to use a regex as shown below, that specifies a match only for exactly 16 digits.  Then you can use the "test" method against the input value and that will return true or false depending on if the value meets the regex pattern.  Add whatever logic you want to handle the result of the test.

  var regex = /^\d{16}$/;
  regex.test(credit0_number.value)

Open in new window


»bp
Avatar of Jazzy 1012

ASKER

I want it to test on the spot before it goes anywhere else so it does not process the form yet.
ASKER CERTIFIED SOLUTION
Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland 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
SOLUTION
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