Expressions, only allow a certain input

Discussion in 'PHP' started by webmasterplace, Apr 16, 2008.

  1. #1
    Hi,

    I need some help with my form.

    <form action="stats.php" method="POST">
    
    Username:<br>
    <input type="text" size="25" class="form" autocomplete="off" maxlength="15" name="buxusername" value="<? echo $row["buxusername"]; ?>">
    <br><br>
    
    Account balance:<br>
    $ <input type="text" size="10" class="form" autocomplete="off" maxlength="15" name="balance" value="<? echo $row["balance"]; ?>">
    <br><br>
    
    Amount of Referrals:<br>
    <input type="text" size="6" class="form" autocomplete="off" size="5" maxlength="15" name="referrals" value="<? echo $row["referrals"]; ?>">
    <br><br>
    
    <font color="#9c1515">*</font> Security code:<br>
    <img src="image.php" onclick="this.src='image.php?newtime=' + (new Date()).getTime();">(Click to reload)<br />
    <input type="text" size="5" class="form" autocomplete="off" maxlength="5" name="code">
    <br><br>
    
    <input type="submit" value="Update">
    
    </form>
    Code (markup):
    As you can see I have an input form Account Balance and Amount of Referrals.
    Well, currently people can submit things like
    Account Balance: lol
    Amount of Referals: o_o

    I want that it only allows numbers in Amount of Referrals
    e.g.
    Amount of Referals: 15
    Amount of Referals: 15236

    and in Account balance some special conditions:
    e.g.
    Account Balance: 10
    Account Balance: 10.00
    Account Balance: 10.000
    Account Balance: 10.0000

    Can somebody help me with this please?
    Thanks in advance!!!
     
    webmasterplace, Apr 16, 2008 IP
  2. webmasterplace

    webmasterplace Peon

    Messages:
    802
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please someone?
    I can't find it!!
     
    webmasterplace, Apr 17, 2008 IP
  3. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #3
    jayshah, Apr 17, 2008 IP
  4. webmasterplace

    webmasterplace Peon

    Messages:
    802
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes it works now!
    Thanks for the links ;)
     
    webmasterplace, Apr 17, 2008 IP
  5. webmasterplace

    webmasterplace Peon

    Messages:
    802
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ow, I have a problem again.

    I use this code now to check the input of Account Balance:
    function isDecimalNumber($n) {
      return (string)(float)$n === (string)$n;
    }
    Code (markup):
    Now it only allows inputs like: 16.13 or 10, but when I try 16.1325 it doesn't work.
    This is my piece of code to check if the input is correct:

    if(isDecimalNumber($balance) == false){ 
    $error = 1;
    $errormsg .= "<b>Error</b> - Your Account Balance is not correct.";
    }
    if($error == 1)
    {
    print $errormsg."<br /><br />";
    
    }
    Code (markup):
    What's wrong with my code?
     
    webmasterplace, Apr 17, 2008 IP
  6. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Any chance of a Positive Rep? :D

    Why not use is_numeric for account balance?

    Jay
     
    jayshah, Apr 17, 2008 IP
  7. webmasterplace

    webmasterplace Peon

    Messages:
    802
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Because if I use is_numeric, it won't allow inputs like 10.5025
    It needs to allow e.g. '10' or '10.50' or '10.5025' and don't allow e.g. 'lol' or '10.502575' so a maximum of 4 numbers after the point.
     
    webmasterplace, Apr 18, 2008 IP