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

Wednesday, February 16, 2022

[FIXED] Regex expression for a rule in yii model validation

 February 16, 2022     pcre, php, regex, yii     No comments   

Issue

I'm trying to figure out a regex to express this string:

 dev_XXX_<name>

where XXX is a 3 digit number and name is already expressed with /[0-9a-zA-Z \- _]/.

This regular expression will be used as a model validation rule in PHP/YII, so it's a PCRE regular expression.

My non-working solution is this one:

/^dev_([0-9]{3})_<([0-9a-zA-Z \- _])>*$/

But it seems to not accept the last major sign.

Thank you for any help & explanations!


Solution

Looks like your asterisk is in the wrong place

/^dev_([0-9]{3})_<([0-9a-zA-Z \- _])>*$/

should be

/^dev_([0-9]{3})_<([0-9a-zA-Z \- _]*)>$/

This will mean that your character set [0-9a-zA-Z \- _] should match zero or more of those characters



Answered By - Pudge601
  • 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