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 8257281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:08:47+00:00 2026-06-08T02:08:47+00:00

I am working on a validator library, coming from PHP I would like to

  • 0

I am working on a validator library, coming from PHP I would like to give the validation a similar set up with Validators and Constraints (The value, object gets validated by the validators against the selected constraints).

So working on the Constraints I have following issue:

The constraints all share the same properties just the implementation is slightly different.

Example:

Constraint = Validator.Constraint = {
    name: null, // contains the name of the constraint
    value: null, // contains the value which we want to validate
    options: {}, // contains options for some Constraints (e.g. range)
    message: null, // contains the error message which is getting returned
    validate: function(){}, // the validation logic
    constructor: function(value, options){ 
        this.value = value;
        this.options = options;
        this.validate(); 
    } // the constructor which can be called for stand-alone validation
};

Now I would like to somehow extend the Constraint and customize it:

RequiredConstraint = Validator.RequiredConstraint = {
    name: "required",
    message: "this property is required",
    validate: function(){
        if (this.value != "" || this.value != undefined || this.value != null) {
            return;
        }
        return this.message;
    }
    // other properties get inherited
};

The constrain then should be usable with:

RequiredConstraint("");
// returns false

I know would like to know two things:

  1. At first if it is at all recommand to use this programming style even JavaScript is another language and too dynamic for this?
  2. If it is still good practis how could I implement such behaviour as descriped above?
    What keywords do I have to look for?

Regards

  • 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-08T02:08:48+00:00Added an answer on June 8, 2026 at 2:08 am

    You need to put your functions in the prototype if you want them to be inherited.

    Also, in ES3, the cleanest objects to inherit from are Functions.

    Example:

    function Constraint() {}
    
    Constraint.prototype = {
        constructor: Constraint,
    
        validate: function() {
            console.log( 'Hello!' );
        },
    
        message: 'Property required!'
    };
    
    var RequiredConstraint = new Constraint();
    
    RequiredConstraint.message; // "Property required!"
    RequiredConstraint.validate(); // "Hello!"
    
    // Now let's override it
    RequiredConstraint.validate = function() {
        console.log( 'Hey!' );
    };
    RequiredConstraint.validate(); // "Hey!"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jquery function as validationtype its working fine <script type=text/javascript> jQuery.validator.addMethod(mytest, function (value,
I would like to use grape to install a library by command-line. So I've
I am trying to get my UniqueEmail validator working but it seems that my
I've written a url validator for a project I am working on. For my
I'm working on a Spring MVC project in which I'm using Hibernate Validator to
I'm working on my xml skills, but validator errors my XSD at certain deep
I'm working on a form in .NET and am using the standard field validators.
I'm managed to get the validation working for the second step and third step
I can't seem to get client side validation working with the version of MVC
Please bear with me. I've got the jQuery validation plugin working beautifully in FF,

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.