CodeIgniter Forums
Preg_match explained - Regex Help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Preg_match explained - Regex Help (/showthread.php?tid=28570)



Preg_match explained - Regex Help - El Forum - 03-15-2010

[eluser]richzilla[/eluser]
Hi all, Im having a bit of trouble getting my head around preg_match as im trying to write some customised validation functions.Basically im trying to validate a price, and what ive come up with so far is this:

Code:
[0-9]+(\.|\,)[0-9][0-9]

However, although that works, as far as i can see, the preg match function returns true if that is matched anywhere in a string, so you could enter complete rubbish:

Code:
aasosdoiasoi10.00idfgisdfgisudfgisdf

would still technically be correct. Is there any php function i can use to make sure my string exactly matches my regular expression?

any help would be appreciated.

Thanks


Preg_match explained - Regex Help - El Forum - 03-15-2010

[eluser]danmontgomery[/eluser]
use ^ for the start of a line, and $ for the end of a line


Preg_match explained - Regex Help - El Forum - 03-15-2010

[eluser]sophistry[/eluser]
great regex site: http://www.regular-expressions.info/