Email Validation by restricting a domain


hello there,
I am currently working over a project which requires 2 validations on email, the first is the email availability of already registered email in database and other is to check whether every email address contains domain name for e.g, is the domain name and it should be check that users with this email can only register otherwise it gives the message of ‘Inavlid email address’. I have successfully implemented my first requirement through the steps in the manual however i am struggling with the second requirement where i want to suffix and restrict ‘’ as my domain. kindly let me know what statement or rule should i be using.


<?php namespace App\Validation\Rules; use App\Models\User; use Respect\Validation\Rules\AbstractRule; class EmailSuffix extends AbstractRule { public function validate($input){ return User::where('email', $input)-> } } //in the above code i need to return a value which checks the domain name and here i am confused. EmailSuffixException.php <?php namespace App\Validation\Exceptions; use Respect\Validation\Exceptions\ValidationException; class EmailAvailableException extends ValidationException { public static $defaultTemplates = [ self::MODE_DEFAULT => [ self::STANDARD => 'Email is invalid', ], ]; }


Maybe combine the existing validation with some other validators like EndsWith:

e.g. v::endsWith('') or Regex or
or the custom callback validator.


Thankyou so much Odan. v::endsWith worked for me! :slightly_smiling_face: