GetDotted Domains

Viewing Thread:
"PHP help : preg_match"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Tue 18/01/05 at 13:25
Regular
"Picking a winner!"
Posts: 8,502
I'm using a function that checks if an e-mail address is of a valid format eg [email protected].

It uses the following to check if its in a valid format.

(!preg_match("/^.+\@(\[?) [a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/", $email))


I got this code from a book but it dosn't explain it too well and I can't really work out whats happening using the manual so I was hoping someone on here might be able to break it down and point out what exactly it does.


Thanks
Tue 18/01/05 at 16:28
Regular
"Picking a winner!"
Posts: 8,502
Thanks a lot. Very helpful.

Understand it now :0)
Tue 18/01/05 at 16:23
Regular
"Party like its 2005"
Posts: 452
This is a 'regular expression'
If you type 'introduction guide regular expression' or something similar into google, you'll get what you need.

EDIT - that walk through the example expression was very useful - thanks Garin :)
Tue 18/01/05 at 16:20
Regular
"Devil in disguise"
Posts: 3,151
Erm..not sure what kind of explanation you want, preg_match is for matching a string with a regular expression. I'll explain the regular expression bit by bit as I guess thats the difficult bit to understand.

^.+

The string starts with at least 1 character(s)

\@

and is followed by an AT symbol.

(\[?)

After the AT symbol there may be a [ but no more than 1.

[a-zA-Z0-9\-\.]+

Followed by a word that is at least 1 character in length and contains only a-z,A-Z,0-9, - or a full stop, eg microsoft, 192.168.0, specialreserve.co are a match,

\.

This word must be followed by a full stop.

([a-zA-Z]{2,3} | [0-9]{1,3})

The | is an OR which means theres 2 possible valid matches for what comes after the full stop.

[a-zA-Z]{2,3}

It can be a word that only contains A-Z and a-z and is a minium of 2 characters but a maximum of 3 characters, eg com, net, uk in the case of domains.

[0-9]{1,3}

OR it can match to a word that only contains numbers and is a minimum of 1 character but a maximum of 3. This is for matching against IP addresses.

(\]?)

After the domain name there may be a ] but no more than 1.

$

Finally the end of the string must also be the end of a line, ie theres no more text after it.

Not a very good explanation I know. But its a start, you are really better reading a tutorial on it and breaking it down yourself, by far the best way to start understanding regular expression.
[URL]http://gnosis.cx/publish/programming/regular_expressions.html[/URL] is fairly nice, works as a reference manual too as I just had to look up some symbols I didn't remember. :)
Tue 18/01/05 at 13:25
Regular
"Picking a winner!"
Posts: 8,502
I'm using a function that checks if an e-mail address is of a valid format eg [email protected].

It uses the following to check if its in a valid format.

(!preg_match("/^.+\@(\[?) [a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/", $email))


I got this code from a book but it dosn't explain it too well and I can't really work out whats happening using the manual so I was hoping someone on here might be able to break it down and point out what exactly it does.


Thanks

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

10/10
Over the years I've become very jaded after many bad experiences with customer services, you have bucked the trend. Polite and efficient from the Freeola team, well done to all involved.
Best Provider
The best provider I know of, never a problem, recommend highly
Paul

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.