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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:48:12+00:00 2026-06-17T22:48:12+00:00

as you might know, within the HTML5 spec we got some new attributes for

  • 0

as you might know, within the HTML5 spec we got some new attributes for <input> elements, such as required and pattern. This provides as a great way of validating user-input and we can even visualize it using CSS and pseudo selectors. Example

HTML

<input type="number" pattern="\d+" required/>

CSS

input:required:valid {
    border: 1px solid green;
}

input:required:invalid {
    border: 1px solid red;
}

If that <input> element would be part of an <form> element, an user wouldn’t be able to submit that in invalid state.

However, my question is, what if we want to use those new attributes without <form> elements ? Is there a way to access the current state of such an <input> node through ECMAscript directly ?

Any event ? Any listener ?

  • 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-17T22:48:14+00:00Added an answer on June 17, 2026 at 10:48 pm

    As pointed out by @Zirak, there is the checkValidity method, part of the Constraint Validation API.

    var s = document.createElement('input');
    s.checkValidity(); // true
    s.required = true;
    s.checkValidity(); // false
    

    However, checkValidity fires an invalid event if it’s invalid. (The form will be red-outlined.) You may want to use the willValidate property (or the .validity.valid property) instead.

    Also, the validity property is quite interesting to watch (more information about what each property means on the Constraint Validation API):

    s.validity
        ValidityState
            customError: false
            patternMismatch: false
            rangeOverflow: false
            rangeUnderflow: false
            stepMismatch: false
            tooLong: false
            typeMismatch: false
            valid: false
            valueMissing: true
    

    This article points out the differences in implementations between the browsers: http://www.html5rocks.com/en/tutorials/forms/constraintvalidation/ (i.e: it’s a mess, as usual.)

    You can also listen to the invalid event, triggered on submit of the form, or when the checkValidity method is called.

    Demo: http://jsfiddle.net/XfV4z/

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

Sidebar

Related Questions

I know this might be very easy to some,, I have a simple string
I know this might sound easy. I thought about using the first dot(.) which
I know this might seem like a duplicate, but I'm not getting anywhere with
I know this might be a stupid question, but here it goes. I always
I know this might be a long shot, but here it goes. I have
I know this might be a bit awkward but I am trying to modify
I know this might seem a controversial question but it really is not meant
I know this might sounds not reasonable, and might be a bad design. But
I know this might be fairly Unity-specific, but the reason I am asking it
I'm pretty new to cron jobs so this might be an easy answer but

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.