PHP String character checks are character characters in the UK or the USA.

What is the easiest or best way in PHP to validate or lie that a string contains only characters that can be entered using a standard US or UK keyboard with a keyboard language set to UK or English?

To be more specific, I mean using a single keystroke with or without using a toggle key.

I think the characters are as follows. 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ~ `! @ # $% ^ & * () _- + = {[}] | \ :; "'<,>.? / ยฃ and Space

+5
source share
3

ASCII [ -~] (.. ). ยฃ ( , ยฑ ยง, ).

- :

if(preg_match('#^[ -~ยฃยฑยง]*$#', $string)) {
    // valid
}
+4

:

/^([a-zA-Z0-9!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~\t ])*$/m

:

$result = (bool)preg_match('/^([a-zA-Z0-9!"#$%&\'()*+,\-.\/:;<=>?@[\\\]^_`{|}~\t ])*$/m', $input);

:

function testUsUkKeyboard($input) 
{
    return (bool)preg_match('/^([a-zA-Z0-9!"#$%&\'()*+,\-.\/:;<=>?@[\\\]^_`{|}~\t ])*$/m', $input);
}
+1

- , , , , , ascii 128 - 255, 0 - 127 .

Tio , :

$chars = range(128,255);

: alt text

then you should check the line in question again, people say they use regex, but I really don't think it is necessary

$ string = "check a simple string";

for($s=0;$s<strlen($string);$s++)
{
    if(in_array(ord($string[$s]),$chars))
    {
        //Invalid
    }
}
0
source

All Articles