MaplePHP
  • MaplePHP - Layered structure MVC PHP framework
  • Guide
    • Get started
    • Installation
    • Service Provider
    • Dependency injector
    • Controller
    • Middlewares
    • Routers
  • Navigation
    • Simple navigation
    • Dynamic navigation
  • Template engine
    • Getting started
    • Templates
      • Index
      • Views
      • Partials
    • Content (DTO)
      • String
      • Number
      • Array
      • DateTime
      • Encode
      • Dom
  • Form builder
    • Form builder
  • Database
    • MySQL
  • Service providers
    • url
    • encode
    • dir
    • DB
    • responder
  • Installations
    • Authorization & login
  • Frontend template
    • Responder
    • Views & components
    • Modals
    • Redirects
  • Access
    • MaplePHP with Docker
  • Libraries
    • Container
    • MySQL queries
    • Validation
    • Cache
    • Logger
    • Request
    • Response
  • What is?
    • Dependency injector
    • Controller
    • Middleware
    • Router
Powered by GitBook
On this page
  • Initiation
  • Check string length is more than or equal to 1
  • Check string length is more/equal than 1 and less/equal than 160
  • Check if is valid email
  • Check if is valid phone
  • Validate Swedish social number (personnummer)
  • Validate Swedish organisation number
  • Validate credit card number
  • Validate VAT number
  • Check if is a color hex code
  • Check date and date format
  • Check date, date format and is between a range
  • Check if persons is at least 18 years old or older.
  • Check if is a valid domain name
  • Check if is a valid URL (http/https is required)
  • Check if is a valid DNS

Was this helpful?

  1. Libraries

Validation

MaplePHP - Validation is a PHP library designed to simplify the process of validating various data inputs. Whether you need to verify if a value is an email or phone number, check for minimum and maximum length constraints, or perform other common validation tasks, MaplePHP - Validation provides a convenient and straightforward solution for handling input validation.

Initiation

You will always initiate instace with the static method _val followed by a value you want to validate.

use MaplePHP\Validate\Inp;

// Validate option 1
$inp = new Inp("Lorem ipsum dolor");
var_dump($inp->length(1, 200)); // true

// Validate option 2
$valid = Inp::value("Lorem ipsum dolor")->length(1, 200);
var_dump($valid); // true

Check string length is more than or equal to 1

Inp::value("Lorem ipsum dolor")->length(1);

Check string length is more/equal than 1 and less/equal than 160

Inp::value("Lorem ipsum dolor")->length(1, 160);

Check if is valid email

Inp::value("john@gmail.com")->email();

Check if is valid phone

Will allow only numbers and some characters like ("-", "+" and " ").

Inp::value("+46709676040")->phone();

Validate Swedish social number (personnummer)

Inp::value("198808213412")->socialNumber();

Validate Swedish organisation number

Inp::value("197511043412")->orgNumber();

Validate credit card number

Inp::value("1616523623422334")->creditcard();

Validate VAT number

Inp::value("SE8272267913")->vatNumber();

Check if is a color hex code

Inp::value("#000000")->hex();

Check date and date format

Inp::value("2022/02/13 14:15")->date("Y/m/d H:i");
// The date argument is the expected date format (will also take time)

Check date, date format and is between a range

Inp::value("2022/02/13 - 2022/02/26")->dateRange("Y/m/d"); 
// The dateRange argument is the expected date format (will also take time)

Check if persons is at least 18 years old or older.

Inp::value("1988-05-22")->age("18");

Check if is a valid domain name

Inp::value("example.com")->domain();

Check if is a valid URL (http/https is required)

Inp::value("https://example.com/page")->url();

Check if is a valid DNS

Will check compare result against DNS server and match A, AAAA and MX

Inp::value("example.com")->dns();

Open the file for a lot more validations.

PreviousMySQL queriesNextCache

Last updated 1 year ago

Was this helpful?