0

My problem on this code is how to input a numbers only and not any letters

my input text

My problem here is it can accept numbers and not letters but the "E" Letter still persists and can accepts it. how to remove it help please thanks

{{Form::number('moviePriceToken', '', ['class' => 'form-control', 'placeholder' => 'Token Price'])}}

1 Answers1

0

So, first off, e is a number. But... you're right, it probably shouldn't be accepted as a number in a form.

Laravel's validator seems to correctly handle it:

$validator = Validator::make(['number' => 'e'], [
    'number' => 'required|numeric',
]);

$validator->passes(); // returns false

And an <input type="number"> correctly rejects it.

enter image description here

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • no sir, i need to constraints when i type it to the form inputs –  Nov 29 '18 at 01:01
  • so how can i remove that when im typing –  Nov 29 '18 at 01:01
  • 1
    If you're referring to *typing* instead of submitting, see the duplicate question I've linked. https://stackoverflow.com/questions/19966417/prevent-typing-non-numeric-in-input-type-number – ceejayoz Nov 29 '18 at 01:02
  • hey sir im not familiar with javascript, jquery or ajax but I have this one line code here and it is perfect for my code ..` ` how can I implement this code type to my form-collective input number above my code? how can i transform it like that –  Nov 29 '18 at 01:06
  • 1
    Probably something like `{{Form::number('moviePriceToken', '', ['class' => 'form-control', 'placeholder' => 'Token Price', 'onkeydown' => 'javascript: return event.keyCode == 69 ? false : true'])}}`. – ceejayoz Nov 29 '18 at 01:07
  • okay you earn a badge thanks –  Nov 29 '18 at 01:09