Jump to content

Archived

This topic is now archived and is closed to further replies.

takeiteasy

Data validation

Recommended Posts

Hi all, can i ask if there's a code for data validation like for example,
i have this
[code]Amt. Paid: SG$  <input type = 'text' name='amtpaid' size='10' maxlength='10'>[/code]
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!

Share this post


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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.