Question

Javascript Assign re with a regular expression that contains an upper-case letter (A-Z) followed by a...

Javascript

Assign re with a regular expression that contains an upper-case letter (A-Z) followed by a dash.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution for the given question are as follows -

Code :

<!DOCTYPE html>
<html>
<body>
<input type="text" id="input" name="input" placeholder="enter any text"/>
<button onclick="checkRegex()">Check Regex</button>
<p id="regex"></p>

<script>
function checkRegex() {
var input = document.getElementById("input").value;
if (input.match(/^[A-Z\-]*$/)) {
document.getElementById("regex").innerHTML =
"Valid Input";
} else {
document.getElementById("regex").innerHTML =
"Invalid Input";
}
  
}
</script>
</body>
</html>

Code Screen Shot :

<!DOCTYPE html <html> <body> <input type text id-input name-input placeholder=enter any text/ <button onclick=checkR

Output :

1)

Check Regex aaa Invalid Input

2)

Check Regex AAA- Valid Input

Add a comment
Know the answer?
Add Answer to:
Javascript Assign re with a regular expression that contains an upper-case letter (A-Z) followed by a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT