Jump to content

Consists of letters or not?


Hamlets666

Recommended Posts

Your regular expression will match only a single character from a-z as it is written.

[b]Match any number of lower case alpha chars, including none:[/b]
"/^[a-z]*$/"

[b]Match any number of lower case alpha chars, at least one:[/b]
"/^[a-z]+$/"

[b]Match at most [i]n[/i] lower case alpha chars, including none:[/b]
"/^[a-z]{[i]n[/i]}$/"

[b]Match between [i]m[/i] and [i]n[/i] lower case alpha chars:[/b]
"/^[a-z]{[i]m[/i],[i]n[/i]}$/"

If you want to learn more:
http://www.regular-expressions.info/tutorial.html
example:
[code]

<?php

function Is_Chars($string)
{
if(preg_match("/^[a-zA-Z]+$/", $string))
return true;
else
return false;
}

// example
if(Is_Chars($_GET['value']))
{
  echo "Value is chars only";
}
else
{
  echo "Not only chars in the value";
}

?>

[/code]

And [color=red]is_nan()[/color] is not a way to check if it is chars only but rather to see if the value is not a number
http://no.php.net/manual/en/function.is-nan.php
So [code=php:0]is_nan()[/code] is like the opposite of [code=php:0]is_numeric()[/code] ?

Though [code=php:0]is_numeric()[/code] will be true against Hexidecimal numbers which or numeric strings which I guess isn't what is being looked for :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.