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

  • SEARCH
  • Home
  • 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 3501524
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:52:11+00:00 2026-05-18T12:52:11+00:00

I am making a generic text validation function with jQuery. I made the function

  • 0

I am making a generic text validation function with jQuery. I made the function text and I pass the id,requirement,expression,offset,limit into the function. The way I have made it is to help me run the function easily on single input change and on the submit of the whole form. I have made the function but I can’t get it to run.

var Val = {
    'text' : function(event, ident,req,regexp,offset,limit) {
        var ele = $(document.getElementById(ident));

        if(req == 1 && ele.val().length < 1) {
            Val.errors = true;
            $("#"+ident+"Error").html("Please enter your " + ele.attr("title"));
            $("#"+ident+"Error").show("fast");
        } else if(ele.val().length <= offset || ele.val().length > limit) {
            Val.errors = true;
            $("#"+ident+"Error").html(ele.attr("title") + " should be between " +offset+ " & " +limit+ " charecters long");
            $("#"+ident+"Error").show("fast");
        } else if(regexp != null) {
            switch (regexp) {
                case 'text':
                    var regEx = /^([a-zA-Z]+)$/; break;
                case 'number':
                    var regEx = /^([0-9]+)$/; break;
                case 'email':
                    var regEx = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; break;
                case 'date':
                    var regEx = /^([123]0|[012][1-9]|31)-(0[1-9]|1[012])-(19[0-9]{2}|2[0-9]{3})$/; break;
                case 'alphanum':
                    var regEx = /^([a-zA-Z0-9._-]+)$/; break;
                default:
                    var regEx = /^([a-zA-Z0-9._-]+)$/; break;
            }
            if(!regEx.test(ele.val())) {
                Val.errors = true;
                $("#"+ident+"Error").html(ele.attr("title") + " is not valid");
                $("#"+ident+"Error").show("fast");
            }
        }
    },

    'send' : function (){
        if(!Val.errors) {
            $('#form').submit();
        }
    }
}

The calling code of the function:

$(document).ready(function(){
    $('#send').click(function(){
        Val.text('test', 1, 'email', 10, 50);
        Val.send(); 
    });

    $('#test').bind('change', Val.text);
    $('#test').trigger('change', ['test', 1, 'email', 10, 50]);
});

I know I haven’t yet used the expressions but I will once I see it working.

Appreciate all the help…

Thanks!

  • 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-05-18T12:52:12+00:00Added an answer on May 18, 2026 at 12:52 pm

    I made it work. Once the script worked properly no trigger was required. I was able to just call simply inside the change event.

    $('#emailID').change(function(){
        Val.text('emailID', 1, 'email', 10, 100);
    });
    

    Thanks everyone for the help anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried making (my first) a C# program: using System; using System.Collections.Generic; using
I have been making my own custom control and I ran into trouble when
I'm just making a generic homepage but the difference is that the text on
Possible Duplicate: Making a generic property I'm not quite sure how to do that,
Making a word document of our network set-up. We have about 7 servers and
I have been writing some code that creates a generic blog. Its features are
I was reading a question on making a generic property , but I'm a
Making a new class in VS10 gives me using System; using System.Collections.Generic; using System.Linq;
I dive into Django making blog. The problem is that after rendering view there
I wanted to get some info/tips on making a Generic (iOS/Android/WebOS/etc...) Mobile Site. Looking

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.