Hi all, I have a small piece of code to check that a field is numeric only,

function validate_numeric($variable) {
	return is_numeric($variable);
}

How can I check that text entered is text only ?
so to protect against malicous attacks. . .

Thanks

Hmmmm. . . Can anyone make any sence of the following -

preg_replace('#[^A-Za-z0-9]#i', '',

To me, the above reads, if a letter or number, replace with nothing ?
Is that right. .

The code:

preg_replace('#[^A-Za-z0-9]#i', '',

Just removes every character in a string that is not a letter or number. The "^" means not in regular expressions, so

[^A-Za-z0-9]

means not anything inside the brackets.

What do you mean “to protect against malicous attacks. . .” , what type of variables do you want to avoid ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.