•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the HTML and CSS section within the Web Development category of DaniWeb, a massive community of 401,683 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,588 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 HTML and CSS advertiser: Lunarpages Web Hosting
Views: 2331 | Replies: 4
![]() |
useing this code I avoid to paste invalid chracters to textboxes.
function PasteAlphaNumeric(objEvent)
{
var strPasteData = window.clipboardData.getData("Text");
var objInput = objEvent.srcElement;
if (strPasteData.search("[^A-Za-z0-9]")!=-1) {
alert("The character you attempted to paste is not allowed for this field.");
objInput.focus();
return false;
}
}
I want to allow to paste white space characters (\s) and[A-Za-z0-9] to the textbox, how can I do this.
function PasteAlphaNumeric(objEvent)
{
var strPasteData = window.clipboardData.getData("Text");
var objInput = objEvent.srcElement;
if (strPasteData.search("[^A-Za-z0-9]")!=-1) {
alert("The character you attempted to paste is not allowed for this field.");
objInput.focus();
return false;
}
}
I want to allow to paste white space characters (\s) and[A-Za-z0-9] to the textbox, how can I do this.
You could use an expression modifier, to add the /s to your character array. I haven't tested it, and it's late, but try:
function PasteAlphaNumeric(objEvent)
{
var strPasteData = window.clipboardData.getData("Text");
var objInput = objEvent.srcElement;
if (strPasteData.search("[^A-Za-z0-9]+/s")!=-1)
{
alert("The character you attempted to paste is not allowed for this field.");
objInput.focus();
return false;
}
} Sorry. Include the "\s" special character within your character class. You'll need to escape the blackslash WITH a backslash. For example this works:
function testRegEx(x)
{
var regex = new RegExp("[^A-Za-z0-9\\s]");
if (x.value.search(regex) != -1)
{
alert("Invalid Entry.");
}
}![]() |
•
•
•
•
•
•
•
•
DaniWeb HTML and CSS Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Help: How to validate a string in datagrid while edit mode (ASP.NET)
- web address validate in javascript (JavaScript / DHTML / AJAX)
- Searching for script to validate member's websites (PHP)
- Data Navigation in textboxes with ADO.NET (like ADO) (ASP.NET)
Other Threads in the HTML and CSS Forum
- Previous Thread: HELP! Html image file!
- Next Thread: rotate pictures in a mapped image space?



Linear Mode