Laravel’s validation system has more than 60 validation rules available, but what if you need other features? You can easily create your own validation rules, or you can use existing validation rules on the Internet. let's see.
22 Rules from Alphametric
First, we start with a series of articles from Matt Kingshott, a senior developer at Alphametric who writes at Medium Wrote many posts and added all the rules to the Github repository. The following is a list of available rules:
StrongPassword: Checks if it is a "strong" type password
TelephoneNumber: Checks if it is a valid phone number
RecordOwner: Requires the authenticated user ID to match the user_id column in the given database record , for example: Owner: Post, id
MonetaryFigure: Check the monetary figure, for example: $ 72.33
DisposableEmail: Checks whether the email address is a disposable email address
DoesNotExist: Checks whether the given value exists
Decimal in database table/column: Check whether it has the correct format of decimal
EncodedImage : Check whether the value is a base64 encoded image of the given mime type
LocationCoordinates: Check whether it is a set of longitude and latitude coordinates separated by commas
FileExists: Check if the value is an existing file path
Equals: Check Is the value equal to another value
MacAddress: Check if the value is a valid MAC address
ISBN: Checks if the value is a valid ISBN-10 or ISBN-13 number
EndsWith: Checks if the value ends with the given string
EvenNumber: Check whether the value is an even number (use intval for decimal type casting first)
OddNumber: Check whether the value is an odd number (use intval for decimal type conversion first)
Lowercase: Check whether the value is a lowercase string
Uppercase: Check whether the value is an uppercase string
Titlecase: Check whether the value is an uppercase string Title string
Domain: Check whether the value is a legal domain name google.com, www.google.com
##CitizenIdentification: Check whether the value is a legal US/French/UK citizen ID number
-
WithoutWhitespace: Check whether the value contains spaces Characters
8 Rules from Scott Robinson
Created by Scott Robinson Another good set of rules, he also created a dedicated website laravel-validation-rules.github.io for this purpose. It has the following rules:
Colour: The value is not a color, currently only hexadecimal codes are supported.
Country Codes: Validates 2&3 character country codes.
Credit Card: Verify whether the value is a legal credit card number and the validity period.
IP: Verifies whether the value IP address is public or private. Supports IPV4 and IPV6.
Phone: Verify whether the value meets the phone number format.
Subdomain: Verify whether the self-domain name value submitted by the user already exists in the current program.
Timezone: Verify that the time zone value is valid in the system time and date database.
-
US State: Verify whether the value is a US state/Canadian province.
Spatie’s 5 Rules
Spatie In your own repository provides some verification rules:
Authorized: Verify whether the user has the authority to perform functions on an instance of a model.
CountryCode: Verifies that the field is a valid ISO3166 country code.
Enum: Verify that the value is part of the given enumeration class, for example myclabs/php-enum.
ModelsExist: Verifies that all values in the input array exist as properties of the given model class.
-
Delimited: Verify whether there is a delimited value in the string, such as @ in 'sebastian@example.com, alex@example.com' Symbol
5 Rules of Pineco.de
Finally from Gergő D. Nagy published an article in pineco at the end of 2017. Relevant validation rules are stored in GitHub repository. But it hasn’t been updated since then, so use with caution! The rules are as follows:
- password: Check the user's password.
- Odd: Check whether the value is odd.
- even: Check whether the value is even.
- incremented: Check whether the value is an auto-increment field.
- specific words: Check whether the value contains a specific word.
weekday: Check whether the date is a legal working day.
Original address: https://laraveldaily.com/40-additional-laravel-validation-rules/
Translation address: https://learnku .com/laravel/t/39365
[Related recommendations: laravel video tutorial]
The above is the detailed content of [Compilation and Sharing] 40 Practical Laravel Form Validation Rules. For more information, please follow other related articles on the PHP Chinese website!

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!
