Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,672 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,176 people online right now. Registration is fast and FREE... Join Now!




xoops validation length function

 
Reply to this topicStart new topic

xoops validation length function, need the ideal the validate input value length

jilong
post 19 Jul, 2007 - 01:38 AM
Post #1


New D.I.C Head

*
Joined: 17 May, 2007
Posts: 32


My Contributions


First, i need some one familiar with xoops,

i did some hack on the edituser.php and function .php to add in the validation on Real Name (only alphabet allow) and telephone (only numbers allow), with the it work code below,

But my problem is i couldn't add the check value length function for postcode. the postcode keyin must be 5 digit, if more or less than 5 digit the error message will show. at bottom i the coding i had try. Hope can get help on here,

code on edituser.php
CODE

$name = '';
        if (!empty($_POST['name'])) {
            $name = $myts->stripSlashesGPC(trim($_POST['name']));
        }
        if ($name == '' || !checkname($name)) {
          $errors[] = _US_NEEDNAME;
        }

$tel_hp = '';
        if (!empty($_POST['tel_hp'])) {
            $tel_hp = $myts->stripSlashesGPC(trim($_POST['tel_hp']));
        }
        if ($tel_hp == '' || !checkphone($tel_hp)) {
            $errors[] = _US_NEEDHP;
        }


code on function.php
CODE

function checkname($name)
{
    if (!$name || !preg_match("/^[a-z @]+$/i",$name)){
        return false;
    }
    return $name;
}

function checkphone($tel_hp)
{
    if (!$tel_hp || !preg_match("/^[0-9-]+$/i",$tel_hp)){
        return false;
    }
    return $tel_hp;
}


Code i try for check length on function.php
CODE


function checkIC($post)
{
for ($i=0; $i<strlen($post); $i++) {
    if ($post.charAt(i) < 5){
        return false;
    }
}
    return $post;
}


User is offlineProfile CardPM

Go to the top of the page

Styx
post 24 Jul, 2007 - 09:53 AM
Post #2


D.I.C Head

Group Icon
Joined: 4 Mar, 2007
Posts: 192



Dream Kudos: 225
My Contributions


If you want to check the length of something, could you say:

CODE
if (strlen($var) != 5)
{
  return false;
}
User is offlineProfile CardPM

Go to the top of the page

jilong
post 27 Jul, 2007 - 01:46 AM
Post #3


New D.I.C Head

*
Joined: 17 May, 2007
Posts: 32


My Contributions


i had do it in this way, it work

CODE

function checkcorpost($cor_post)
{
    if (!$cor_post || !preg_match("/^\d{5}$/i",$cor_post)){
        return false;
    }
    return $cor_post;
}
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:11AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month