need regex for community builder
Moderator: General Moderators
-
gato_de_botas
- Forum Newbie
- Posts: 6
- Joined: Mon May 03, 2010 4:35 pm
need regex for community builder
hi, I need a regex to use in Community Builder, with Joomla, to mask a field like this
XXX.XXX.XXX-XX (where X = numbers)
I tried many options suggested by many people, but none are working, I dont know why. See the options I tried:
^\d{3}\.\d{3}\.\d{3}-\d{2}$
\^\d{3}\.\d{3}\.\d{3}-\d{2}$\
/^\d{3}\.\d{3}\.\d{3}-\d{2}$/
and many other options I see in the Regex Library, at http://regexlib.com/ but nothing is working.
What regex I should use, please write exactly in the way I will have to write.
thanks!
XXX.XXX.XXX-XX (where X = numbers)
I tried many options suggested by many people, but none are working, I dont know why. See the options I tried:
^\d{3}\.\d{3}\.\d{3}-\d{2}$
\^\d{3}\.\d{3}\.\d{3}-\d{2}$\
/^\d{3}\.\d{3}\.\d{3}-\d{2}$/
and many other options I see in the Regex Library, at http://regexlib.com/ but nothing is working.
What regex I should use, please write exactly in the way I will have to write.
thanks!
-
gato_de_botas
- Forum Newbie
- Posts: 6
- Joined: Mon May 03, 2010 4:35 pm
Re: need regex for community builder
Here another expressions I tried, from Regex Library:
(^\d{3}\x2E\d{3}\x2E\d{3}\x2D\d{2}$)
(\d{3}.?\d{3}.?\d{3}-?\d{2})
(^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$)
(^(\d{2}.\d{3}.\d{3}/\d{4}-\d{2})|(\d{14})$)|(^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$)
None of them is working, and I am in doubt about using ( and ), and also / and \ at the beginning and end of the expressions. Seems that Community Builder needs a delimiter, but I dont know which to use.
Help please!
thanks
(^\d{3}\x2E\d{3}\x2E\d{3}\x2D\d{2}$)
(\d{3}.?\d{3}.?\d{3}-?\d{2})
(^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$)
(^(\d{2}.\d{3}.\d{3}/\d{4}-\d{2})|(\d{14})$)|(^(\d{3}.\d{3}.\d{3}-\d{2})|(\d{11})$)
None of them is working, and I am in doubt about using ( and ), and also / and \ at the beginning and end of the expressions. Seems that Community Builder needs a delimiter, but I dont know which to use.
Help please!
thanks
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: need regex for community builder
You didn't describe the format of your typical data. i.e. Do you have a long string with this pattern embedded in it? Or does the whole string consist of just the one field to be matched?
Try one of these:
If you are going to work with regular expressions, you'll need to spend a little time to learn the proper syntax required by the PHP preg_* functions. You need to first take your regex say: '\d{3}' and wrap it in delimiters (which can be any non alpha-numeric), like so '%\d{3}%'. Choose a delimiter that is not in the regex pattern (the most common choice is '/' - I have used '%' here). Then you place any modifiers you need after the closing delimiter (such as 'i' for "ignore-case mode", 'm' for "multi-line mode", etc.) Then wrap the whole pattern in a single quoted string. This is then passed to the preg_* function like so: preg_replace('%\d{3}%im', 'replacetext');
Hope this helps!
Try one of these:
Code: Select all
// Case 1. The target to be matched is the whole string. (Use ^ and $ anchors)
if (preg_match('/^\d{3}\.\d{3}\.\d{3}-\d{2}$/m', $contents)) {
# Successful match
} else {
# Match attempt failed
}
// Case 2. The target to be matched is embedded in a larger string. (Use \b anchors)
if (preg_match('/\b\d{3}\.\d{3}\.\d{3}-\d{2}\b/m', $contents)) {
# Successful match
} else {
# Match attempt failed
}Hope this helps!
-
gato_de_botas
- Forum Newbie
- Posts: 6
- Joined: Mon May 03, 2010 4:35 pm
Re: need regex for community builder
thanks runner,
The number is a CPF - a document format used in Brazil, like 444.555.666-77
I have only a field to enter the expression, see this image, I have to enter the expression in the Perl Regular Expression, just one line of text:

I am confused, please write exatly in the way I have to write in the field, without any other caractheres like ' or (, use only what I have to write.
The number is a CPF - a document format used in Brazil, like 444.555.666-77
I have only a field to enter the expression, see this image, I have to enter the expression in the Perl Regular Expression, just one line of text:

I am confused, please write exatly in the way I have to write in the field, without any other caractheres like ' or (, use only what I have to write.
-
gato_de_botas
- Forum Newbie
- Posts: 6
- Joined: Mon May 03, 2010 4:35 pm
Re: need regex for community builder
runner,
I found this expression in a php file pointed by the error message, give a look:
$validated = preg_match( $pregExp, $value );
if ( ! $validated ) {
$pregExpError = $field->params->get( 'pregexperror', CBTxt::T('Not a valid input') );
$this->_setValidationError( $field, $user, $reason, $pregExpError );
}
}
}
return $validated;
}
}
I found this expression in a php file pointed by the error message, give a look:
$validated = preg_match( $pregExp, $value );
if ( ! $validated ) {
$pregExpError = $field->params->get( 'pregexperror', CBTxt::T('Not a valid input') );
$this->_setValidationError( $field, $user, $reason, $pregExpError );
}
}
}
return $validated;
}
}
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: need regex for community builder
Ok, so you are NOT writing PHP code yourself. This helps. Try this one first:
[text]^\d{3}\.\d{3}\.\d{3}-\d{2}$[/text]
[text]^\d{3}\.\d{3}\.\d{3}-\d{2}$[/text]
-
gato_de_botas
- Forum Newbie
- Posts: 6
- Joined: Mon May 03, 2010 4:35 pm
Re: need regex for community builder
thanks again, Runner
I got an error message "NOT A VALID INPUT" and "Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\wamp\www\joomla\components\com_comprofiler\plugin\user\plug_cbcore\cb.core.php on line 74"
I tried adding the slashe \ at the beginning and end of the expression, but got the same result.
What do you think?
I got an error message "NOT A VALID INPUT" and "Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\wamp\www\joomla\components\com_comprofiler\plugin\user\plug_cbcore\cb.core.php on line 74"
I tried adding the slashe \ at the beginning and end of the expression, but got the same result.
What do you think?
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: need regex for community builder
Ok that info helps. The community builder code requires that you supply the Perl regular expression with regex delimiters. Good. Try this one next:
[text]/^\d{3}\.\d{3}\.\d{3}-\d{2}$/[/text]
[text]/^\d{3}\.\d{3}\.\d{3}-\d{2}$/[/text]
-
gato_de_botas
- Forum Newbie
- Posts: 6
- Joined: Mon May 03, 2010 4:35 pm
Re: need regex for community builder
thanks Runner,
this time only the message "Not a valid input".
I entered the expression
/^\d{3}\.\d{3}\.\d{3}-\d{2}$/
and tried the numbers 222.333.444-55
this time only the message "Not a valid input".
I entered the expression
/^\d{3}\.\d{3}\.\d{3}-\d{2}$/
and tried the numbers 222.333.444-55
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: need regex for community builder
I'm not sure what to say. The regex provided is the correct one to match your data pattern but the tool you are using evidently does not like it.
I have no familiarity with this "Community builder" software and don't have time to investigate what might be causing the problem. However, you may want to experiment with the Perl regex option using some simpler data and matching patterns...
Good luck - rr
I have no familiarity with this "Community builder" software and don't have time to investigate what might be causing the problem. However, you may want to experiment with the Perl regex option using some simpler data and matching patterns...
Good luck - rr