This topic is locked

Validating number lengths

5/4/2007 11:15:52 AM
PHPRunner General questions
M
mrpeeble author

I want to validate a number for length = 9 and then display a message to the user if it is too short or too long. any help would be appreciated.

Sergey Kornilov admin 5/7/2007

Easier solution - set maxlength parameter of Edit box to 9 characters.

M
mrpeeble author 5/7/2007

I did that.
The problem is it allows the user to save memberIDs of less than 9. If the user enters more than 9, the record simply does not save and the user does not get a warning message of any kind. I need to validate the data as exactly 9 numbers ( no letters or weird spaces) and display an error if the user enters something else.

Easier solution - set maxlength parameter of Edit box to 9 characters.

L
larsonsc 5/7/2007

I think you could use a BeforeRecordAdd event to do this

if strlen($values[FieldName]) != 9 {

echo "You must enter 9 characters into the blahblahblah field. Please verify your data.";

$returnvalue = false;

}
else {

$returnvalue = true

}
return = $returnvalue;


My syntax in the evaluation line might be off, but I think this should get you started.

Sergey Kornilov admin 5/7/2007

In general this code is correct. Just a couple of minor fixes.

if (strlen($values["FieldName"]) != 9)

{

echo "You must enter 9 characters into the blahblahblah field. Please verify your data.";

return false;

}

return true;
L
larsonsc 5/7/2007

Well I was close. ;-) Thanks for the fix-up.

M
mrpeeble author 5/8/2007

Well I was close. ;-) Thanks for the fix-up.


Yes, thank you that fixed it!
I will now attempt to put the error reply in a message box with retry button.

L
larsonsc 5/8/2007

If you get the message box function working, could you please share the code with me? I would much prefer to have my error messages like this pop up in a message box rather than text at the top of the screen. I'd appreciate the help if you could share the code once you get it working! Thanks!

M
mrpeeble author 2/11/2008

If you get the message box function working, could you please share the code with me? I would much prefer to have my error messages like this pop up in a message box rather than text at the top of the screen. I'd appreciate the help if you could share the code once you get it working! Thanks!


//better late than never
if (strlen($values["MemberID"]) != 9)

{

echo '<script language=javascript>alert("You must enter 9 characters into the member ID field. Please verify your data.")</script>';

return false;

}
//test

return true;