You are here: Re: Regular Expressions « All PHP « IT news, forums, messages
Re: Regular Expressions

Posted by Martie on 05/04/06 03:03

On 3 May 2006 13:03:17 -0700, tomhawkins1@gmail.com wrote...
>
>I can never seem to get these to do what I want and it should be simple
>as far as I can tell! I need to check to see if a variable of mine has
>been submitted in the correct format.
>
>The 'correct' format is either
>1. 8-15@113.5
>ie a number (an integer between 1 and 500 say), followed by one '-'
>followed by a number (an integer between 1 and 500 say), an @ and a
>number to end (a float between 1 and 10000 say), or
>
>2. 43@226 ie without the first '8-'
>
>Any guidance as I'm tearing my hair out.!?
>
>Thanks
>
>Tom
>

May be worth trying something using the "preg_match()" function. With the first
example you had I was able to get that to work with the following. Though I did
just catch the potential for "501", so it needs a littel more tweaking.

$var = '8-15@113.5';
if(preg_match('/^[1-5]*[0-9]*[1-9]+\-[1-5]*[0-9]*[1-9]+\@[1-9]+[0-9.]*$/',
$var))
{

}


--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация