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: //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
236 Like 34 Dislike
Previous forums Next forums
Other forums

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

Saving PHP output as a file
I wondered if anyone knows how to save the rendered output of a PHP script as a file?

I have

help removing unwanted graphic
How do I remove the small elongated rectangular shape between the "Latest post" and "

Question handling xml data
Hello,

I have sucessfull followed this tutorial
http://www.phpfreaks.com/tutorial/handlin

How do i use vars in an array
Hiya peeps!

How do I use a var in an array. You will see $id but it isnt working.


Displaying an image using echo command
I had done a query on my database, one of the fields being an image reference to a directory where a

Just wondering what you think about my site
I am new to phpfreaks i just seen this form and thought it would be cool to see what other thought a

Request for tunning the below query
Hi,

Can any one help me on the below query while improving the performance,

 formating when pulling data from a mysql database 
Ok so Im not to sure if this is the right thread to post in but here is my catch 22 issue.

I

"SEO" URLs
Hey, I'm wondering how to go about creating and using these types of URLs. I'm presuming it's PHP th

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