function checkparagraph(obj) {
var paragraphContent = obj.value;
var sequenceOfNumbers = /\d{4}/;
if (paragraphContent.match(sequenceOfNumbers)) {
document.getElementById("error_message").innerHTML = " You can't use numbers in the description.";
document.getElementById("error_message").className = "showErrorMessage";
} else {
document.getElementById("error_message").className = "hideErrorMessage";
}
}
.contentWrapper {
width: 100%;
height: 100%;
}
.content_50 {
width: 400px;
margin-top: 50px;
margin-left: 50px;
}
.hideErrorMessage {
display: none;
}
.showErrorMessage {
display: block;
color: red;
}
<DOCTYPE! html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div class="contentWrapper">
<div class="container">
<textarea id="paragraph" name="description" rows="20" cols="66" onblur="checkparagraph(this)"></textarea>
<span id="error_message" class="hideErrorMessage"></span>
</div>
</div>
</body>
</html>
I have implemented JavaScript for paragraph validation. The paragraph should not contain more than 4 sequences of numbers (i.e., 1234).
The required format is to have a space between two 4-sequence numbers before displaying an error message. How can I merge these two regular expressions?