Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:37:20+00:00 2026-06-12T00:37:20+00:00

My Jquery code basically validates a textbox’s value on copy-paste This code applies to

  • 0

My Jquery code basically validates a textbox’s value on copy-paste
This code applies to many input fields in multiple pages. All the pages use a common JavaScript file and a common Layout page

var regex = /^[A-Za-z0-9AEIOUaeiou\.\-\~\`\'']*$/;
$('#InputField1').bind('input propertychange', function () {
    var value = $(this).val();
    if (!regex.test(value)) {
        $(this).val("");
    }
});

Instead of writing this on every page, is there any way to make this code more generic?? That is, could the following part of the code be written just once somewhere on the layout page or JavaScript page??

var value = $(this).val();
if (!regex.test(value)) {
    $(this).val("");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:37:21+00:00Added an answer on June 12, 2026 at 12:37 am

    This is one of the awesome things about jQuery. You can do this in a global JavaScript file:

    (function($){  
     $.fn.validatePropertyChange = function() {  
    
        return this.each(function() {
             var self = $(this);
             var regex = /^[A-Za-z0-9ĀĒĪŌŪāēīōū\.\-\~\`\'']*$/;
                 $(self).bind('input propertychange', function () {
                 var value = $(this).val();
                 if (!regex.test(value)) {
                      $(this).val("");
                 }
              });
        });  
     };  
    })(jQuery);
    

    Then just call:

    $('#InputField1').validatePropertyChange();
    

    And you can also chain the Ids, such as:

    $('#InputField1, #InputField2').validatePropertyChange();
    

    and use CSS selectors too

    $('.required-field').validatePropertyChange();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following jquery code. basically - it takes a value from an
I have this jquery code: $.each('.button.gobutton', function() { alert($(this).attr('title')); }); I basically want to
I'm using the JQuery DropdownChecklist as available from here: http://code.google.com/p/dropdown-check-list/ Basically I'm using some
I'm having some trouble with finding the visibility param for JQuery. Basically... the code
My jquery code It's not working when $(a).on(hover,function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); But is working when $(a).hover(function(){$(this).css(background,#ccc);},function(){$(this).css(background,#fff)}); How
I have the following jQuery code: $(ul.menu li a).click(function() { $(ul.menu li a).removeClass(currentMenu); $(this).addClass(currentMenu);
I have this simple jQuery code to test out. <html> <head> <script type=text/javascript src=jquery.js></script>
Nick Craver really helped me out alot with this code in this thread jQuery
Could someone point me in the right direction here? Basically, I've got this jQuery
I have the following code for the jQuery validation plugin.... basically on submit, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.