Jump to content

Recommended Posts

Hello guys i need a little bit of help with this. I need the regex for example - ULUS-12345

 

Broken down into 4 parts (UL) (US) (-) (12345)

 

The first part can be either UL or UC

The second part can be wither US or ES or JP

The third part must be a dash

The forth part must consist of 5 numbers.

 

Thank You

Brandon_R

  • 2 weeks later...

Well, given your initial post explanation, my pattern would satisfy this.. so either your explanation is incomplete / inaccurate, or there is more to the info than you have given. As CV is hinting, simply stating it isn't working doesn't help us at all. The only thing I can think of off the top of my head is to perhaps try removing the initial ^ and trailing $ character (as this checks from beginning of string to end of string). If the sample along the lines of ULUS-12345 is in the middle of a larger string, the pattern will fail.

 

Please give us some complete sample strings so that we can see why it isn't working. Without much info to go by, it's rather difficult to troubleshoot, wouldn't you think?

-Post the code in which you tried the pattern in

-Post example content you're trying to match

-Post what the actual error is

 

For real, it continues to boggle my mind how many people lack the basic common sense to post more than "it doesn't work"

	/**
* Verifies that the game region id  is valid
*
* @param	string numbers and/or letters
*
* @return	
*/
function verify_game_region_id(&$game_region_id)
{
	if (!preg_match('#^U[LC](?:[uE]S|JP)-[0-9]{5}$#', $game_region_id));
	{
		return false;
	}
}

 

 

Basically  i want it to match wither ULUS-12345 or UCUS-12345 or UCJS-12345. The last 5 digits must be numbers.

 

Thanks for all your help so far guys

Brandon_R

Basically its what users type in the form and i catch it with a post like $game_region_id = $_POST

 

It looks like this

 

ULUS-12345 or UCUS-12345 or UCJS-12345

 

Ok, so if it's in a post that users enter info from, then it's possible that this info could be part of a larger message? If so, try the initial regex pattern without ^ or $

 

if (!preg_match('#U[LC](?:[uE]S|JP)-[0-9]{5}#', $game_region_id))

 

By the way, looking at your previous snippet, I just noticed that you have a semicolon  at the end of the if line.. You'll need to remove that (as I have done in this snippet I just provided).

Here is the code that runs the function:

 

	var $validfields = array(
	'gamecodearchiveid'			=> array(TYPE_UINT,		REQ_INCR,	VF_METHOD,	'verify_nonzero'),
	'gamecodearchivename'			=> array(TYPE_STR,		REQ_YES,	VF_METHOD,	'verify_gamecodearchivename'),
	'gamecodearchiveregionid'		=> array(TYPE_STR,		REQ_YES,	VF_METHOD,	'verify_gamecodearchiveregionid'),
	'gamecodearchiveregion'			=> array(TYPE_UINT, 		REQ_YES,	VF_METHOD,	'verify_gamecodearchiveregion'),
	'gamecodearchivecodes'			=> array(TYPE_STR,		REQ_YES,	VF_METHOD,	'verify_gamecodearchivecodes')
);

 

as You can see its the 3rd 1 down that defines the function to verify the input then goes on to save. thats basically it I already posted the finction above. If the reges isnt working could you guys just give me 1 that checks (4 letters then a dash then 5 numbers)? Dont worry about the exact letters.

I cant belive i didnt see this.

 

if (!preg_match('#^U[LC](?:[uE]S|JP)-[0-9]{5}$#', $game_region_id)); <--- look at the ';' that doesnt belong there.

 

Thanks anyways guys, wasnt the regex :)

 

Yes, I know.. hence from my previous post:

 

By the way, looking at your previous snippet, I just noticed that you have a semicolon  at the end of the if line.. You'll need to remove that...

 

Please don't forget to mark this thread as solved.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.