0

Javascript:

  function textonly(e) {
        var code;
        if (!e) var e = window.event;
        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;
        var character = String.fromCharCode(code);
        var AllowRegex = /^[\ba-zA-Z\s-]$/;
        if (AllowRegex.test(character)) return true;
        return false;
    }

Html:

<asp:TextBox ID="textbox1" onkeypress="return textonly(event);" runat="server"></asp:TextBox>

I am trying to allow only text.If i use textonly event in above js function,

i can not press key below:

ğ,ü,ş,i,ö,ç and Space

how can i also include above values on key press ?

1 Answer 1

1

You can just extend your regex like this:

^[\ba-zA-Z\sğüşöç\s]$

This will allow one character of the below:

\b a backspace character (ASCII 8)
a-z a single character in the range between a and z (case sensitive)
A-Z a single character in the range between A and Z (case sensitive)
\s match any white space character [\r\n\t\f ]
ğüşöç a single character in the list ğüşöç literally (case sensitive)
\s match any white space character [\r\n\t\f ]

Sign up to request clarification or add additional context in comments.

1 Comment

thanks it works except " ı " how can i also include " ı " ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.