0% found this document useful (0 votes)
9 views2 pages

Regex

Uploaded by

jagtaptanay80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Regex

Uploaded by

jagtaptanay80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

<html>

</head>

<body>

<h1>Simple Regex Validation</h1>

<p>Enter text to check if it contains only letters (A-Z or a-z):</p>

<input type="text" id="textInput" placeholder="Enter text here">

<button onclick="validateText()">Validate</button>

<p id="result"></p>

<script>

function validateText() {

// Regular expression to check for letters only

const regex = /^[a-zA-Z]+$/;

// Get user input

const input = document.getElementById('textInput').value;

// Check input against the regex

if (regex.test(input)) {

document.getElementById('result').textContent = "Valid input: Only


letters!";

document.getElementById('result').style.color = "green";

} else {

document.getElementById('result').textContent = "Invalid input:


Contains non-letter characters.";
document.getElementById('result').style.color = "red";

</script>

</body>

</html>

You might also like