Home: Perl Programming Help: Regular Expressions:
PERL Regular Expression for a validation form



vladik86
Novice

Feb 12, 2015, 10:39 AM


Views: 32107
PERL Regular Expression for a validation form

Hello all...
To begin with, i don't know PERL and my english is bad, so, Iíll try to explain you what i need.
I need Regular Expression that can validate a form having this syntax XXX.YYY.XYYY.X (where X are letters and Y are numbers)... so, in total, 5 letters 6 numbers and 3 dot.
I am not sure I managed to explain myself. I hope you can help me.


FishMonger
Veteran / Moderator

Feb 12, 2015, 11:08 AM


Views: 32106
Re: [vladik86] PERL Regular Expression for a validation form

/^[a-z]{3}\.\d{3}\.[a-z]]d{3}\.[a-z]$/i


vladik86
Novice

Feb 12, 2015, 11:16 AM


Views: 32104
Re: [FishMonger] PERL Regular Expression for a validation form


In Reply To
/^[a-z]{3}\.\d{3}\.[a-z]]d{3}\.[a-z]$/i


Thanks, i tried, but this expression validate only a "dot". i can put only number with 3 "dot" at the end, and the field is validated anyway


FishMonger
Veteran / Moderator

Feb 12, 2015, 11:25 AM


Views: 32099
Re: [vladik86] PERL Regular Expression for a validation form

That regex will match the exact pattern that you stated.

Does your string contain anything else besides the pattern that you need to match?

Please post the string that you're needing to validate and the code you used to do the validation.

EDIT:
Oops, I see a typo in the regex which breaks it. Change it to this:

Code
/^[a-z]{3}\.\d{3}\.[a-z]\d{3}\.[a-z]$/i



(This post was edited by FishMonger on Feb 12, 2015, 11:34 AM)


vladik86
Novice

Feb 12, 2015, 11:32 AM


Views: 32096
Re: [FishMonger] PERL Regular Expression for a validation form

There are the serial number of each operator
exsample string: CPS.045.F110.U or FAS.451.Y435.Q


FishMonger
Veteran / Moderator

Feb 12, 2015, 11:36 AM


Views: 32091
Re: [vladik86] PERL Regular Expression for a validation form

Remove the start and end anchors.

Code
/[a-z]{3}\.\d{3}\.[a-z]\d{3}\.[a-z]/i



vladik86
Novice

Feb 12, 2015, 11:50 AM


Views: 32089
Re: [FishMonger] PERL Regular Expression for a validation form

Don't work "Not a valid input"
I tried to use both uppercase and lowercase


(This post was edited by vladik86 on Feb 12, 2015, 11:51 AM)


FishMonger
Veteran / Moderator

Feb 12, 2015, 11:51 AM


Views: 32086
Re: [vladik86] PERL Regular Expression for a validation form

Post your code!!


vladik86
Novice

Feb 12, 2015, 12:06 PM


Views: 32082
Re: [FishMonger] PERL Regular Expression for a validation form

I haven't a code...it's a configuration for one joomla registration form http://puu.sh/fPxWx/8edc931bce.png


FishMonger
Veteran / Moderator

Feb 12, 2015, 12:18 PM


Views: 32077
Re: [vladik86] PERL Regular Expression for a validation form

I have no idea how your joomla registration form processes and tests the regex so I can't say why it doesn't validate.

Here's my test code and results that show that the regex DOES validate the pattern/string you specified.

Code
c:\test>type validate.pl 
#!/perl

use strict;
use warnings;

my $str = 'CPS.045.F110.U or FAS.451.Y435.Q';

if ($str =~ /[a-z]{3}\.\d{3}\.[a-z]\d{3}\.[a-z]/i) {
print "Valid Input\n";
}
else {
print "Invalid Input\n";
}


Code
c:\test>validate.pl 
Valid Input



FishMonger
Veteran / Moderator

Feb 12, 2015, 12:23 PM


Views: 32073
Re: [vladik86] PERL Regular Expression for a validation form

You might need to post your question on a forum specifically related to joomla.


vladik86
Novice

Feb 12, 2015, 12:25 PM


Views: 32071
Re: [FishMonger] PERL Regular Expression for a validation form


In Reply To
You might need to post your question on a forum specifically related to joomla.


I already tried ... they said "you have to know PERL" ... so, thank you anyway


Zhris
Enthusiast

Feb 12, 2015, 6:44 PM


Views: 32064
Re: [vladik86] PERL Regular Expression for a validation form

Based on the image you provided, assumably you won't want the / and /i at the start and end, they are Perl syntax, Joomla support should be able to confirm this. Replace the case insensitive i modifier with [a-zA-Z] character classes instead if necessary.

Chris


(This post was edited by Zhris on Feb 12, 2015, 6:57 PM)


vladik86
Novice

Feb 13, 2015, 12:48 PM


Views: 32041
Re: [vladik86] PERL Regular Expression for a validation form

Ok, now works. Probably had some problems, I reinstalled everything and now works perfectly. I wanted to thank you very much for your help on behalf of our entire association of volunteers. Thank you.