PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 30, 2022

[FIXED] How to combine these regex expressions together

 July 30, 2022     laravel, laravel-request, php, regex, validation     No comments   

Issue

I'm working with Laravel and I have used this custom regular expression for validating user password request:

'user_password'=> ['required','min:6','regex:/[a-z]/','regex:/[A-Z]/','regex:/[0-9]/','regex:/[@$!%*#?&]/']

Now I needed to combine these separated regexs all together but don't know how to do it, so if you know, please let me know.. thx!


Solution

One general way to do this via a single regex would be to use positive lookaheads to assert each requirement:

/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[@$!%*#?&]).{6,}$/

The above pattern says to match:

^                 from the start of the user password
(?=.*[a-z])       at least one lowercase letter
(?=.*[A-Z])       at least one uppercase letter
(?=.*[0-9])       at least one digit
(?=.*[@$!%*#?&])  at least one special character
.{6,}             then match any 6 or more characters
$                 end of the password


Answered By - Tim Biegeleisen
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing