I’m using rules in validation in Laravel, and am trying to check the number of characters in a number. This is my attempt: Unfortunately that checks that the zip code is the number 5 and not that the zip code is 5 characters. Which rules do I need to set to check that the zip code is exactly 5 characters,
Tag: validation
How to give custom field name in laravel form validation error message
I was trying form validation in laravel. I have a input text field in my form called ‘Category’ and i’m given the field name as ‘cat’ as short. And i defined the validation rules like this. When the validation fails i’m getting error message like this But i want to display it as “The category field is required” instead of
Laravel Form Validation, fail if not empty
I have an input field which needs to be empty, otherwise I want the validation to fail. This is an attempt at stopping spam through a contact form. I’ve looked at the documentation for the validation but there’s nothing to do this, other than the “max” rule, but this doesn’t work. Any other options? Answer In the method where you
Laravel: Validation unique on update
I know this question has been asked many times before but no one explains how to get the id when you’re validating in the model. My validation rule is in the model so how do I pass the ID of the record to the validation rule. Here is my models/User models/BaseModel Answer One simple solution. In your Model In your
How does this whitelist array affect $_POST data inside the foreach()?
I’m confused as to exactly what this does and how do you use it in your form processing. Does it only remove unwanted $_POST entries that are not in $expected[]? Should I still use $_POST[ ‘carModel’] to get the value? Or might there be a better way? Answer Right, the pseudo-code ${$variable} is the creation of a new variable, aka:
What’s the best way to validate numbers with comma as decimal separator?
In a Laravel app, I have a form on which I need to validate numbers with a comma as the decimal separator. For the moment, it only works with a point because my validation rule is: What’s the best method : Keep the rule and replace comma with point before validation ? Is there a before_validation observer or something like
PHP Regular Expression for Bengali Word/Sentence
I am developing a web application using PHP 5.3.x. Everything is working fine, but unable to solve an issue due to regular expression problem with Bengali Punctuation. Following is my code: Whether I pass Bengali word or not, it always returns false. In JavaEE application I used this Regular Expression But in PHP it not working! Anyways how do I
Symfony2 Validating an optional field
In my form, I have a field with required option set to false, this field is optional. However, I would like to have a notBlank validation on this field when the field is used: Right now, I can’t use the validation constraint NotBlank because it will cause my form validation to fail when the field is unused. I tried something
php date validation
Im trying to to set up a php date validation (MM/DD/YYYY) but I’m having issues. Here is a sample of what I got: Answer You could use checkdate. For example, something like this: A more paranoid approach, that doesn’t blindly believe the input:
PHP checkdate variants
I found a php function checkdate() , but strangely enough it only seems to accept data in format of int $month , int $day , int $year. However I am passing the date as a string (example “2012-06-13”) …