Web Design Forum: PHP number validation - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP number validation Rate Topic: -----

#1 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 03 August 2009 - 06:42 PM

I have a number field on my form and i want to validate it with php.

But i need condition to see if its a mobile or a UK number.

I have the theory behind it down, where in respect i have to check the numstring count to see if it matches 11 or 12 numeric characters. but the thing is, people write out their numbers different like some people prefere to write mobile numbers out as 00000 000 000 and some 00000000000 same with land lines, Just trying to find the code to validate if its a number.

I was just wondering how i would go about the differences in number input?

Ben
0

#2 User is offline   Faevilangel 

  • Wordpress Ninja.....
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,166
  • Joined: 11-May 09
  • Reputation: 57
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 03 August 2009 - 06:53 PM

you could try preg_match and also strip the spaces not sure the code but something like stripslashes
0

#3 User is offline   BritZin 

  • Lord High Guru
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 940
  • Joined: 02-January 09
  • Reputation: 72
  • Gender:Male
  • Location:United Kingdom
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 03 August 2009 - 06:54 PM

Simple, just strip out the whitespace characters.
It doesn't matter how people enter them, just run a validation that removes whitespace, that way all numbers entered will be returned as a 11/12 sole digit string.

Eg:

 preg_replace(' ','',$NUMBER_VARIABLE); 
 

0

#4 User is offline   irn3rd 

  • Expert
  • PipPipPipPip
  • View gallery
  • Group: Members
  • Posts: 512
  • Joined: 13-July 08
  • Reputation: 3
  • Gender:Male
  • Location:UK
  • Experience:Beginner
  • Area of Expertise:I'm Learning

Posted 03 August 2009 - 07:01 PM

View PostSLGWN2P, on 03 August 2009 - 06:54 PM, said:

Simple, just strip out the whitespace characters.
It doesn't matter how people enter them, just run a validation that removes whitespace, that way all numbers entered will be returned as a 11/12 sole digit string.

Eg:

 preg_replace(' ','',$NUMBER_VARIABLE); 
 


Didn't think it would be as simple as that, should be easy enough to implement :)

Thanks again.
0

#5 User is offline   skidz 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,047
  • Joined: 24-November 08
  • Reputation: 135
  • Gender:Male
  • Location:Derby
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 04 August 2009 - 10:12 AM


      $phone = ereg_replace('[^0-9]', '', $_POST['phone']);

      if (!filter_var($phone, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^0[1-9][0-9]{8,9}$/")))) {

      echo 'Please enter your phone number correctly';

      }

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users