Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
allow numeric and "blank" only
Old 01-11-2008, 09:40 PM allow numeric and "blank" only
Novice Talker

Posts: 7
Trades: 0
I need to make an iput field restricted to only numbers or being left empty. I have this now, which does not permit empty field:
Code:
  if (!is_numeric($auction_item1))
  {
    $error = true;
      $messageStack->add('silentauction', 'Leave empty, or enter only numbers in your bid input box!');
}
What is the proper code for it? Thank you very much.
Veronika
Veronika7747 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-11-2008, 10:02 PM Re: allow numeric and "blank" only
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
PHP Code:
if( ($auction_item1 !='') && (!is_numeric($auction_item1)) ){
    
$error true;
    
$messageStack->add('silentauction''Leave empty, or enter only numbers in your bid input box!');

That way, the !is_numeric check is done only when the field is not empty.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-11-2008, 10:09 PM Re: allow numeric and "blank" only
Novice Talker

Posts: 7
Trades: 0
Quote:
Originally Posted by tripy View Post
PHP Code:
if( ($auction_item1 !='') && (!is_numeric($auction_item1)) ){
    
$error true;
    
$messageStack->add('silentauction''Leave empty, or enter only numbers in your bid input box!');

That way, the !is_numeric check is done only when the field is not empty.
Thank you so much!!
Veronika7747 is offline
Reply With Quote
View Public Profile
 
Old 01-11-2008, 10:46 PM Re: allow numeric and "blank" only
Novice Talker

Posts: 7
Trades: 0
Quote:
Originally Posted by tripy View Post
PHP Code:
if( ($auction_item1 !='') && (!is_numeric($auction_item1)) ){
    
$error true;
    
$messageStack->add('silentauction''Leave empty, or enter only numbers in your bid input box!');

That way, the !is_numeric check is done only when the field is not empty.
ah, but now it does not give me an error message when apha letters are inputed...
Veronika7747 is offline
Reply With Quote
View Public Profile
 
Old 01-11-2008, 11:30 PM Re: allow numeric and "blank" only
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Change && to ||
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 01-12-2008, 12:13 AM Re: allow numeric and "blank" only
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Just to add, it might be better to use a regular expression to account for white space.

PHP Code:
if(ereg('^[\s0-9]*$'$auction_item1) === false){
    
$error true;
    
$messageStack->add('silentauction''Leave empty, or enter only numbers in your bid input box!');



BTW - Is this from ZenCart or OSCommerce?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-12-2008, 05:47 AM Re: allow numeric and "blank" only
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Sorry, I misunderstood you.
I thought you wanted the check to be done only if a value was in $auction_item1.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-12-2008, 11:47 AM Re: allow numeric and "blank" only
Novice Talker

Posts: 7
Trades: 0
Quote:
Originally Posted by mgraphic View Post
Just to add, it might be better to use a regular expression to account for white space.

PHP Code:
if(ereg('^[\s0-9]*$'$auction_item1) === false){ 
PHP Code:
[color=black]    $error true;[/color]
[
color=black]    $messageStack->add('silentauction''Leave empty, or enter only numbers in your bid input box!');[/color]
[
color=black]} [/color
BTW - Is this from ZenCart or OSCommerce?
I am learning ZenCart, but the auction product type does not work so I am making ordinary form for the bids. Do you know/have auction product type that would work with Zencart??
Veronika7747 is offline
Reply With Quote
View Public Profile
 
Old 01-12-2008, 10:24 PM Re: allow numeric and "blank" only
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by Veronika7747 View Post
I am learning ZenCart, but the auction product type does not work so I am making ordinary form for the bids. Do you know/have auction product type that would work with Zencart??
Hmmm, no I don't, but the zencart website has tons of modules to download and may have something contributed for that ability already.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to allow numeric and "blank" only
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.62549 seconds with 12 queries