how to disable special characters in a textbox/textarea?
can anybody please show me how can i disable special characters in a textbox/textarea? im still not very skillful in javascript so i wanted to ask anyone to help me,tnx in advance
Which special characters? Or maybe it is easier to specify which characters should be allowed. RegExp could be useful for this job
i only want to allow 0-9 and a-z and ñ and Ñ,can you show me an example of what you suggested?tnx
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/JavaScript">
function valid(f) {
!(/^[A-zÑñ0-9]*$/i).test(f.value)?f.value = f.value.replace(/[^A-zÑñ0-9]/ig,''):null;
}
</script>
</head>
<body><br>
<form id="myform" action="">
<input name="mytext" type="text" onkeyup="valid(this)" onblur="valid(this)">
</form>
</body>
</html>
wow it worked! tnx your a life saver man,one thing though when i try the ñ and Ñ it still get deleted...
In works for me. Well yes, I have no Spanish keyboard (thus I can not test onkeyup), but if I copy/paste the characters Ññ, they remain in the field. But it theory should work the same onkeyup as onblur.
What charset do you use? iso-8859-1 ?
Maybe use the unicode versions?
Code:
function valid(f) {
f.value = f.value.replace(/[^a-z\u00D1\u00F10-9]*/ig,'');
}
I have no Spanish keyboard either, so I cannot check.
Great wit and madness are near allied, and fine a line their bounds divide.
How to disallow characters ñÑ in the textfield?
Originally Posted by
jagh
How to disallow characters ñÑ in the textfield?
As it is described above.
Thanks, it works. But the space is not allowed to input. I need space to input two names in textbox/textarea (e.g. Maria Ana). How can i define it to this code:
!(/^[A-zÑñ0-9]*$/i).test(f.value)?f.value = f.value.replace(/[^A-zÑñ0-9]/ig,''):null;
Code:
!(/^[A-zÑñ0-9-\s ]*$/i).test(f.value)?f.value = f.value.replace(/[^A-zÑñ0-9-\s ]/ig,''):null;
Read more about regular expressions in javaScript :
http://lawrence.ecorp.net/inet/samples/regexp-intro.php
Hello!
function valid(f) {
f.value = f.value.replace(/[^A-zÑñ0-9-\s]/ig,'')
}
Works perfect! But, how can i change this to can write . : ! , characters?
Can anyone help me?
[A-zÑ.ñ0-9-\s\.\:\!]
This worked for me.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks