check for only characters in a string
Moderator: General Moderators
-
dream2rule
- Forum Contributor
- Posts: 109
- Joined: Wed Jun 13, 2007 5:07 am
check for only characters in a string
Hello All,
I would like to know a method to check for characters in a given string.
i.e, if the string contains any number(or numbers) an error message should pop up.
Only when the string contains all characters, the data must be inserted into a table or else an error message should pop up.
is_string() considers even numbers if they are specified in quotes.
I don't want that to occur as the field is of type string, only characters need to be inserted into the table.
Any functions in PHP that would do this??
Regards,
Dream2rule
I would like to know a method to check for characters in a given string.
i.e, if the string contains any number(or numbers) an error message should pop up.
Only when the string contains all characters, the data must be inserted into a table or else an error message should pop up.
is_string() considers even numbers if they are specified in quotes.
I don't want that to occur as the field is of type string, only characters need to be inserted into the table.
Any functions in PHP that would do this??
Regards,
Dream2rule
- mikeeeeeeey
- Forum Contributor
- Posts: 130
- Joined: Mon Jul 03, 2006 4:17 am
- Location: Huddersfield, UK
-
dream2rule
- Forum Contributor
- Posts: 109
- Joined: Wed Jun 13, 2007 5:07 am
- mikeeeeeeey
- Forum Contributor
- Posts: 130
- Joined: Mon Jul 03, 2006 4:17 am
- Location: Huddersfield, UK
Have you read the documentation?
so all you'd need is...
or am I missing something?
Code: Select all
Return Values
Returns TRUE if var is a number or a numeric string, FALSE otherwise.Code: Select all
if(is_numeric($your_var)){
//code to be executed
}-
dream2rule
- Forum Contributor
- Posts: 109
- Joined: Wed Jun 13, 2007 5:07 am
- mikeeeeeeey
- Forum Contributor
- Posts: 130
- Joined: Mon Jul 03, 2006 4:17 am
- Location: Huddersfield, UK
Code: Select all
if(!is_numeric($your_var)){
//code to be executed
}- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Re: check for only characters in a string
You need to get your terminology straight. A digit is one of 01234567890 (in english and most latin alphabets). A number is something like 123 or -456.789, but can also be +1.2e-25 or even 0xCafeBabe. A (non-unicode) character is every symbol possible in current encoding, which usually includes 256 different symbols. A letter (in the english alphabet) is A, B etc till Z. A string is a sequence of characters. A numeric string is a string that looks like a number.dream2rule wrote:Hello All,
I would like to know a method to check for characters in a given string.
i.e, if the string contains any number(or numbers) an error message should pop up.
Only when the string contains all characters, the data must be inserted into a table or else an error message should pop up.
is_string() considers even numbers if they are specified in quotes.
I don't want that to occur as the field is of type string, only characters need to be inserted into the table.
Any functions in PHP that would do this??
Now, when you know that, can you tell us, what your question is?
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
ctype_alpha()dream2rule wrote:I want to check for alphabetical characters not numbers!