Jump to content


Photo

Data validation


  • Please log in to reply
1 reply to this topic

#1 takeiteasy

takeiteasy
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 03 July 2006 - 05:07 AM

Hi all, can i ask if there's a code for data validation like for example,
i have this
Amt. Paid: SG$  <input type = 'text' name='amtpaid' size='10' maxlength='10'>
and in my database, the type is Varchar(10).

Currently, it can store any kinds of character, but what i wanted is only numbers and decimals to be stored into the database.
So is there any code or way that the system will check if it is only numbers and decimals den it can be added to the database, if not a prompt to inform the user that only numbers can be proceed.

TIA!

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 03 July 2006 - 03:02 PM

You could use ereg() in your processing script, maybe something like:
if(ereg("[0-9]*\.[0-9]{2}",$amtpaid)) echo "Everything is OK";
If you want to do this prior to your processing, you'd need to use a client side language, such as JavaScript.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users