Avatar of ipjyo
ipjyoFlag for United States of America

asked on 

Which Key Event should we use for validating special characters?

Hi,
Currently I have a TEXTAREA as attached.
In the onkeyup event, it will check for special characters and stop them while entering themselves.It is working fine.
But when I tried to copy some text with special characters from a notepad and paste it in the TEXT AREA, the validation is not working. I guess it is because of the "onkeyup" event.
Could you please suggest me how to resolve this.  This validation should work in both the cases ie when typing in the text area as well as when copy and paste.
Thank you for your help!
<TD><TEXTAREA rows="18" cols="32" id="ITextArea" name="ITextArea" onfocus="limitTextarea(this,9999,30)" onkeyup="valid(this)" style="{width:305px; font-family: courier, 'courier new', monospace;}"></TEXTAREA></TD> 
 
function valid(field) 
		{
		var re = /^[a-zA-Z0-9\n\r\f]*$/;
		if (!re.test(field.value)) 
			{
			field.value = field.value.replace(/[^a-zA-Z0-9\n\r\f]/g,"");
			}
		}

Open in new window

JavaScriptASP

Avatar of undefined
Last Comment
ipjyo
ASKER CERTIFIED SOLUTION
Avatar of MMDeveloper
MMDeveloper
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ipjyo
ipjyo
Flag of United States of America image

ASKER

Thanks..it is working now.
I included onchange as well as onkeydown.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo