User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,376 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,736 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1786 | Replies: 6
Reply
Join Date: Dec 2007
Posts: 307
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX's Avatar
OmniX OmniX is online now Online
Posting Whiz

Help Validation - Paste (Ctrl V)

  #1  
Jan 21st, 2008
I was helping a fellow daniweb user with validation for restricting output to only numerics.
Then another user said even it validates a user could copy and paste into the cell.
Now that has been annoying me and I have been trying to figure out a way to prevent this.

Any Ideas? Thanks, Regards X

<html>
<head>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> 
function Numbers(e) {
var cc = (e.which) ? e.which : event.keyCode;
if (cc > 47 && cc < 58) {
return true;
}
return false;
} 
</SCRIPT>
</head>
<body>
<form method="">
<input type="text" name="jtitle" onKeyPress="return Numbers(this)"
size="57">
</body>
</html>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: London, England
Posts: 57
Reputation: hooray is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: Validation - Paste (Ctrl V)

  #2  
Jan 21st, 2008
woo that was me

Maybe there is a way to stop the user from pressing the control key (maybe display an alert box when they press control in the box) obviousley the same applies to right-click and paste, and edit then paste (from the toolbar) i dont know how to get around those with javascript.
Reply With Quote  
Join Date: Jan 2007
Posts: 2,410
Reputation: MidiMagic is on a distinguished road 
Rep Power: 6
Solved Threads: 99
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Posting Maven

Re: Validation - Paste (Ctrl V)

  #3  
Jan 21st, 2008
You don't have the right to take over the user's computer.

And there are three other ways to paste without using the keyboard.

Instead, you should make your script reject any non-numeric input and ask for a correct entry.

Booong! "Entry must be a number" {OK}
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Dec 2007
Posts: 307
Reputation: OmniX is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
OmniX's Avatar
OmniX OmniX is online now Online
Posting Whiz

Re: Validation - Paste (Ctrl V)

  #4  
Jan 22nd, 2008
It has nothing to do with taking over the user's computer...

I just dont wish for input not to be copy n pasted into the textfield of MY website...

So this is not possible via javascript?
Reply With Quote  
Join Date: Mar 2006
Posts: 36
Reputation: sree22_happy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
sree22_happy's Avatar
sree22_happy sree22_happy is offline Offline
Light Poster

Re: Validation - Paste (Ctrl V)

  #5  
Jan 23rd, 2008
yes we can do it in javascript
this is the method to be called
function noCTRL(e)
{
var code = (document.all) ? event.keyCode:e.which;
var ctrl = (document.all) ? event.ctrlKey:e.modifiers & Event.CONTROL_MASK;
var msg = "Sorry, this functionality is disabled.";
if (document.all)
{
if (ctrl && code==86) //CTRL+V
{
alert(msg);
window.event.returnValue = false;
}
else if (ctrl && code==67) //CTRL+C (Copy)
{
alert(msg);
window.event.returnValue = false;
}
}
else {
if (ctrl==2) //CTRL key
{
alert(msg);
return false;
}
}
} 


Password :<input type="text" value=""/><br/>
    Confirm Password :<input type="text" value="" onkeydown="return noCTRL(event)"/>

if this answer helps you please mark as solved
Reply With Quote  
Join Date: Sep 2005
Posts: 606
Reputation: digital-ether will become famous soon enough digital-ether will become famous soon enough 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Re: Validation - Paste (Ctrl V)

  #6  
Jan 23rd, 2008
Attach an event to the onchange property that will check the whole value of the input, not just the key pressed.

It would be slow, and decrease usability a lot. I'd recommend something along the lines of what MidiMagic said. Like attaching an event to onblur or the form submission etc...
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,730
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 323
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Validation - Paste (Ctrl V)

  #7  
Jan 23rd, 2008
> Now that has been annoying me and I have been trying to figure out a way to prevent this.
Doing so wouldn't be a good idea unless it's absolutely necessary. Sure you can do it, but it won't be worth the kind of computational complexity it introduces.

Long gone are the days of client side validation. Just do server side validation and you won't have to worry about what the user pastes or writes in the text box.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 3:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC