How can we use java script to restrict the use of non-ascii characters in a specific text field..? thanks in advance...
Return value The isascii() function returns a boolean value where True indicates that the string contains all ASCII characters and False indicates that the string contains some non-ASCII characters.
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" .
RegexBuddy's regex engine is fully Unicode-based starting with version 2.0. 0.
Using. Bring out the command palette with CTRL+SHIFT+P (Windows, Linux) or CMD+SHIFT+P on Mac. Type Remove Non Ascii Chars until you see the commands. Select Remove non Ascii characters (File) for removing in the entire file, or Remove non Ascii characters (Select) for removing only in the selected text.
Ascii is defined as the characters in the range of 000-177 (octal), therefore
function containsAllAscii(str) {
return /^[\000-\177]*$/.test(str) ;
}
console.log ( containsAllAscii('Hello123-1`11'));
console.log ( containsAllAscii('ábcdé'));
You probably don't want to accept non-printing characters \000-\037
, maybe your regex should be /\040-\176/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With