is there a way to validate the pattern of an input by it's event object (without using a form)?
something like:
<input type='email' onChange={e => e.isPatternOk} />
Beat me to it :), glad you figure it out
Below uses pure css AND a js solution, pick your fancy
.status * {
display: none;
margin-bottom: 20px;
}
input:valid+.status .valid {
display: inline-block;
background: limegreen;
}
input:invalid+.status .invalid {
display: inline-block;
background: red;
}
<input id="textfield" type="text" pattern=".{3,}" required/>
<div class="status">
<span class="invalid">input is invalid</span>
<span class="valid">input is valid</span>
</div>
<input type=button onclick="document.getElementById('js-result').innerHTML = 'Input is valid: '+ document.getElementById('textfield').validity.valid;" value="Check with JS" />
<fieldset>
<legend>JS Result</legend>
<div id="js-result"></div>
</fieldset>
<input oninput="if (re.test(this.value)) ...."