ctype() validation - allowing illegal characters


Posted on 16th Feb 2014 07:03 pm by admin

Hello,
I use ctype() to filter and validate a user form. However, I am trying to allow certain characters.

Example:
Did you know?Explore Trending and Topic pages for more stories like this.

Code: [Select]//Validate Copay
$allow = array('$', '.');

if (!empty($copay) && strlen($copay) < 6 || strlen($copay) > 8) { // IF copay is not empty and not between 6 and 8 characters
$error .= 'COPAY has a maximum of 8 characters. An example of a maximum $0000.00, and a minimum $00.00.<br />';
$output_form = true;
}

if (!empty($copay) && !ctype_digit(str_replace($allow), '', $copay)) { // IF copay is not empty and contains illegal characters (Allow $ and .)
$error .= 'COPAY contains illegal characters.<br />';
$output_form = true;
}
With this example, my test comes back containing illegal characters. I've tried changing it here and there, but get the same results. Thank you!
No comments posted yet

Your Answer:

Login to answer
308 Like 50 Dislike
Previous forums Next forums
Other forums

Adding meta tags under Zend FW
Hello there, recently has come to my hands the FTP of a website which is running under Zend, I would

PHP loop
Okay so I have several "articles" stored in a mysql database and am attempting to echo tho

Setting condidtions for an input box
Hi all,

I would like to set a condition in a txt box that says the number a user enters has t

help understanding hidden input w/ php
hello i'm doing a tutorial where there are multiple forms for an edit page for a user to update thei

How would I convert this into code using an if statement?
ES equals exam score m equals $mean s equals $total. I already coded my mean and total so I'm not g

help with this code please?
Hello,

I am trying to build a remote upload script for my image hosting site.

I am usi

scandir clients directory
hi,
how can i scandir the clients directory? i need a script that when i click a button it will u

Dynamic links in an include file
I am working on a small piece of code that counts records from a database and displays the result to

Greek characters in php
Hi,

I'm making a script and I m using for first time greek characters.
I started to write

duplicate record notification
In my database, after insertion of records, I want to know if the record inserted is duplicate or no

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash