I need help with text and number entry form

Discussion in 'PHP' started by canaryspace, Jan 10, 2008.

  1. #1
    I want to modify an option box that only accepts numbers so that it will accept numbers and characters. Here is the code...



    $numerr = "";
    if($_POST['price'] && !preg_match("/^[0-9\.]*$/", $_POST['price']))
    $numerr .= "- $xsubcatpricelabel<br>";

    if(is_array($data['x']))
    {
    foreach ($data['x'] as $fldnum=>$val)
    {
    if($xsubcatfields[$fldnum]['TYPE'] == "N" && !preg_match("/^[0-9]*$/", $val))
    {
    $fldname = $xsubcatfields[$fldnum]['NAME'];
    $numerr .= " &nbsp; - {$fldname}<br>";
    }
    }
    }

    if($numerr) $err .= "&bull; $lang[ERROR_POST_MUST_BE_NUMBER]<br>$numerr";

    if($err) $err = $lang['POST_ERRORS'] . "<br><br>" . $err;




    Can anyone work out how to allow both numbers and characters.


    Cheers

    Simon
     
    canaryspace, Jan 10, 2008 IP
  2. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $numerr = "";
    if($_POST['price'] && !preg_match("/^[0-9azAZ\.]*$/", $_POST['price'])) 
    $numerr .= "- $xsubcatpricelabel<br>";
    
    if(is_array($data['x']))
    {
    foreach ($data['x'] as $fldnum=>$val)
    {
    if($xsubcatfields[$fldnum]['TYPE'] == "N" && !preg_match("/^[0-9azAZ]*$/", $val))
    {
    $fldname = $xsubcatfields[$fldnum]['NAME'];
    $numerr .= " &nbsp; - {$fldname}<br>";
    }
    }
    }
    
    if($numerr) $err .= "&bull; $lang[ERROR_POST_MUST_BE_NUMBER]<br>$numerr";
    
    if($err) $err = $lang['POST_ERRORS'] . "<br><br>" . $err;
    
    
    Code (markup):
     
    lfhost, Jan 10, 2008 IP
  3. canaryspace

    canaryspace Well-Known Member

    Messages:
    1,320
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Sorry still doesnt work. Im really stuck. Thankyou anyway.
     
    canaryspace, Jan 10, 2008 IP
  4. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    have you worked out at which stage it is failing to recognise the chars? looks fine to me.

    try echoing out each stage and making error messages something you can reference to easy i.e. adding erro 1 error 2 etc etc....
     
    lfhost, Jan 13, 2008 IP