Jump to content

Data validation


takeiteasy

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!
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.