Welcome to WebmasterWorld Guest from 54.147.10.12

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

validate form help

need to check how value starts

     
7:11 am on Nov 3, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Mar 9, 2006
posts:177
votes: 0


Hello,

I need help writing a code that will check if the first characters are http. I am accepting web adresses but don't want any values entered with the [....]

Thanks,
Matt

10:57 am on Nov 3, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2004
posts:941
votes: 0


you can use the strpos() function

or

str_replace("http://", '', $my_string);
This will work even if no http is present

8:24 pm on Nov 3, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Sept 10, 2004
posts:126
votes: 0


If you wanted to display a message to your user, you could use a regex expression to check to see if http:// is present.

if(preg_match("/^http:\/\//i", $input)) {
echo 'Sorry, http:// is invalid input.';
}

3:26 am on Nov 4, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 14, 2008
posts:2910
votes: 62


Duplicate thread:
[webmasterworld.com...]

Not using Regular Expressions and why is briefly discussed.