This is a discussion on "[SOLVED] playing with Perl Compatible Regex in field validation" within the JavaScript Forum section. This forum, and the thread "[SOLVED] playing with Perl Compatible Regex in field validation are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] playing with Perl Compatible Regex in field validation
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
The field validation never ends!
So at the moment the code currently rips any non numerical character and replaces it with literally nothing. It then checks to see if the entry is a number and if not raises an alert. then with if else commands the javascript checks to see that the number is no greater or less than 11 digits long. The code looks like this:
1.let the '+' character through when replacing characters. 2.If the '+' is not the first character in the sequence after this then raise an alert. 3.If it is the first character and is followed by '44' then return true if not then raise an alert. 4.Allow a 14 digit number to return true only if it starts with '0044' Any ideas?? Thanks again for all of the help so far. If I notice that anyone has posted something I can help with I will definetly pitch in. Dan. |
|
|
|
|||
|
Re: playing with Perl Compatible Regex in field validation
anyone??? Im still stuck on this.
|
|
||||
|
Re: playing with Perl Compatible Regex in field validation
Here's a little test page I wrote. See if you can run with this regex:
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
phone number field validation
Im building a phone number field validation. Its getting there but im running into problems.
Please take into account im builiding it only for the uk. so +44 and +0044 interntaional call numbers apply! Ok so far my code is at this state..
1. a alert if you enter nothing 2. lets through 0044********** 3. lets through +44********** 4. lets through 0********** 5. Throws up an error if the number is under 11 characters (if it applies to rule number 4) 6. Throws up an alert if the number is over 11 characters (if it applies to rule number 4) But. The strange thing is, that it will: accept any number for the 0044 rule eg.3546 accept any number for the +44 rule eg.+55 accept any character accept any number for the 0 rule eg 1 I cant see why. Can anyone else??? |
|
||||
|
Re: playing with Perl Compatible Regex in field validation
Have you tried c010depunk's regex from above? It will do a validation on all you need to check at once.
The code would look something like
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Last edited by Rakuli; Oct 26th, 2007 at 10:41. |
|
||||
|
Re: playing with Perl Compatible Regex in field validation
Amen, bro. Regex RockZ!!!
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: playing with Perl Compatible Regex in field validation
yes that would work. But i need seperate alert boxes to make the user aware of where they have made the mistake. You would of thought they could just figure that out themselves. Stupid users!!!
I think my problems boil down to this chunk of code...
|
|
||||
|
Re: playing with Perl Compatible Regex in field validation
Don't capitalise the second 's' in subStr.
Use temp.substr(0,2) etc.... PS. I would place an example number next to the field then fail the submission if it didn't match the regex... The user can see the example if they are wondering how to enter it.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: playing with Perl Compatible Regex in field validation
You know Rakuli you were right with the regex stuff i think now. But I have a question about the way that works...
the {9} part - is this the number of characters allowed??? this does seem like the best way to do it as I can just add...
thanks dan. |
|
||||
|
Re: playing with Perl Compatible Regex in field validation
Hi eon201,
Thanks go to c010depunkk for the regex, I just popped it in your code You know you wouldn't even need the second part of the code as the match checks that the post is the right length... But I guess if you *need* the user to see that they can't remember their number it can't hurt.. lol
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: playing with Perl Compatible Regex in field validation
Im sorry about this. You guys must be sick of me now.
so currently the code works and looks like this!!!
I just want them to get an alert if they put more than 13 characters in for +44 , 14 characters for 0044 , and 11 characters for hte normal 0 number. im actually starting to get this javascript malarky. although I think you boys are safely well ahead of me!! Thanks AGAIN. Dan. |
|
||||
|
Re: playing with Perl Compatible Regex in field validation
here comes a regex explanation:
"/" --> start deliminator "^" --> anchor at the beginning of the string "(" --> open IF statement "\+44" --> literal character string "+44" "[0-9]{9}" --> match 9 digits "|" --> OR "0044" --> literal character string "0044" "[0-9]{10}" --> match 10 digits ")" --> close IF statement "$" --> anchor end of string "/" --> end deliminator
Last Blog Entry: 10 Reasons Why My Laptop Is Better Than Your Girlfriend (Dec 15th, 2007)
|
|
|||
|
Re: playing with Perl Compatible Regex in field validation
ok when when you say "[0-9]{10}" --> match 10 digits your telling javascript to expect 10 digits after the literal character string??
|
|
||||
|
Re: playing with Perl Compatible Regex in field validation
LOL - tag team..
Yep, that's exactly what this is doing. It is the characters 0-9
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: playing with Perl Compatible Regex in field validation
yay! ive got something right! lol
Any ideas on how to get the code to check if the numbers are to long or short from this point now?? thanks. Dan. |
|
||||
|
Re: playing with Perl Compatible Regex in field validation
The thing is that the regex will check the pattern and if the patter matches the string will be the correct length.
If you wanted you could throw in one more (possibly redundant) check.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Last edited by Rakuli; Oct 26th, 2007 at 11:35. |
|
|||
|
Re: playing with Perl Compatible Regex in field validation
Ah ive seen what you have done. But the three different number styles have different numbers of characters overall. eg. a +44 number has 13 characters whilst the 0044 number has 14 , and the normal entry has just 11. T
his is why its such a pain. Especially when I have to warn the user when the value is below or above the correct number!! Thanks.Dan |
|
|||
|
Re: playing with Perl Compatible Regex in field validation
anyone now how to implement the less or more than function when using the regex, but have different values for each number type???
Also ive added another number type in and i have broken the code
|
|
||||
|
Re: playing with Perl Compatible Regex in field validation
Do you have to though? lol...
If it's really required, can do your length checks after the match fails..
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
|
|
|||
|
Re: playing with Perl Compatible Regex in field validation
Hey Rakuli, it's me AGAIN.
can you have a look at this for me... For some reason that I cant spot the problem. The only alerts that seems to work are the first two.. why is this?? Have I done something stupid again???
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] Regex | alexgeek | JavaScript Forum | 3 | Dec 23rd, 2007 16:52 |
| [SOLVED] Field validation and changing display properties... | c_martini | JavaScript Forum | 12 | Sep 25th, 2007 11:27 |
| Non-text field Validation | NewDesigner | JavaScript Forum | 6 | Nov 24th, 2006 22:34 |
| [SOLVED] Convert script to NS6 compatible - Please Help! | Anonymous User | JavaScript Forum | 1 | Feb 20th, 2005 02:35 |
| Field Validation HELP! | Monie | JavaScript Forum | 5 | Nov 11th, 2004 19:46 |