JSFiddle - React, Tailwind, and code Playground
by bschafer
HTML
<input id="cve" value="CVE-20" />
<span id="cve_validation" style="color: Red; font-size: 0.8em;">Enter a CVE</span>
CSS
html {
padding: 5px;
font-family: Arial;
}
JavaScript
function validateCVE(cve) {
// check to see that the input value is not null and is longer than 0 in length
var cve_input = $("#cve");
var val_span = $("#cve_validation");
if (cve !== undefined && cve.length > 0)
{
var isCVE_re = /CVE-20\d{2}-\d{4}/;
var checkCVE = String(cve).search(isCVE_re);
if (checkCVE == -1) {
val_span.html("Not a Valid CVE [CVE-XXXX-XXXX]");
cve_input.css("background-color", "#FFFFC8");
}
else {
val_span.html("Valid CVE");
cve_input.css("background-color", "#FFF");
alert('... and the crowd goes WILD!');
}
}
else {
val_span.html("Enter a CVE");
cve_input.css("background-color", "#FFF");
}
}
$(function () { // this is the jquery ready function
// jQuery keyup handler
// http://api.jquery.com/keyup/
$('#cve').keyup(function() {
// get the value of the input field
var input = $('#cve').val();
validateCVE(input);
});
});