Web Design Forum: how to make telelphone number field of my form accept only numbers - 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

how to make telelphone number field of my form accept only numbers Rate Topic: -----

#1 User is offline   adsegzy 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 55
  • Joined: 15-February 10
  • Reputation: 1

Posted 14 March 2010 - 03:45 PM

Hello friends, i need my telephone field of my form to accept only numbers and not alphabets & other characters, how do i do that?

regards
0

#2 User is online   rallport 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 3,503
  • Joined: 03-January 10
  • Reputation: 247
  • Gender:Male
  • Location:England, UK
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 14 March 2010 - 03:47 PM

I always used a jquery plugin - http://digitalbush.c...d-input-plugin/ - allows you put an input mask on fields.

However, this is only client side and you should be checking the input server side too.
0

#3 User is offline   Wickham 

  • Web Guru
  • View gallery
  • Group: Moderators
  • Posts: 2,682
  • Joined: 11-June 09
  • Reputation: 233
  • Gender:Male
  • Location:Salisbury UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 14 March 2010 - 04:49 PM

View Postadsegzy, on 14 March 2010 - 03:45 PM, said:

Hello friends, i need my telephone field of my form to accept only numbers and not alphabets & other characters, how do i do that?

regards


This is what I used:-
# elseif(eregi('[^][0-9]' , $rating))
# {echo "<p>Please only use numbers 0 to 9 inclusive.<br>Use your back button to <span style=\"color: red;\">try again</span>.</p>";}


The elseif may be different, it depends on the format of your PHP code.

[^] means NOT so it's checking if the input is not a number, if so, it shows the error text.

I also see that eregi is deprecated http://php.net/manua...ction.eregi.php but is still useable until PHP 6 (not released yet) when another function will have to be used (but I'm not sure which).
0

#4 User is offline   jnicol 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 52
  • Joined: 15-March 10
  • Reputation: 0
  • Gender:Male
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 03:33 AM

View PostWickham, on 14 March 2010 - 04:49 PM, said:

I also see that eregi is deprecated http://php.net/manua...ction.eregi.php but is still useable until PHP 6 (not released yet) when another function will have to be used (but I'm not sure which).


preg_match()

http://php.net/manua....preg-match.php
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