Skip to content Skip to sidebar Skip to footer

Accept Characters Only Available On The English Keyword Using Javascript

I have a Javascript function like this: function validateSessionName() { var session_name = document.getElementById('session_name').value; var submitButton = document.getElemen

Solution 1:

It depends what you mean by "English keyboard" and "weird characters".

You're probably thinking of limiting your input to ASCII characters, but even then you can get "weird" characters such as null, and a host of control characters. Perhaps limiting the characters to the ASCII range [32, 126] is what you're after? (Those are all printable characters that can be input on a US keyboard.)

/^[\x20-\x7E]+$/

The characters that match that regex are (note the leading space):

  ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

Solution 2:

Post a Comment for "Accept Characters Only Available On The English Keyword Using Javascript"