I want to input only numbers while entering and restrict characters.
{!! Form::input('text','advertisement_height',null,['class'=>'form-control']) !!}
I want to input only numbers while entering and restrict characters.
{!! Form::input('text','advertisement_height',null,['class'=>'form-control']) !!}
The Laravel validation class comes with a bunch of different number validators: https://laravel.com/docs/5.2/validation#available-validation-rules
You can see there is integer and numeric. If you have the request in your control you could just write the rules for it.
// on your controller
public function store(Request $request)
{
$rules = ['advertisement_height' => 'required|numeric'];
$this->validate($request, $rules);
}
or you can create a validation object and run the validation on your input, however you get it.
Try it here!
<input id="txtnum" onkeypress="return isNumber(event)" type="text" name="txtnum">
Note that digits are allowed and alphabetic characters are not allowed. Observe, too, that arrow keys and backspace are allowed so that you can still edit what you type.
function isNumber(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
Possible Answer: Allow only numbers to be typed in a textbox
Fiddle: http://jsfiddle.net/Lm2hS/
Instead of "text" say "number":
Form::input('number'....
I think Form::number()...
doesn't exist any more
{{Form::number('name','default_text',array('class' => 'form-control', 'required'))}}
use 'number' instead of 'text' and 'required' attribute for mandatory field.