Javascript works except for it needs to flag a string that has first two letters
ID: 3636283 • Letter: J
Question
Javascript works except for it needs to flag a string that has first two letters as uppercase and rest as lowercase - here's what I have so far:ad>
<title>ssn Checker</title>
<script type="text/javascript">
var RE_SSN = /[A-Z][a-z]2/;
function tst_name(ssn){
if (RE_SSN.test(ssn)) {
alert("VALID name");
} else {
alert("INVALID name");
}
}
</script>
</head>
<body>
<form>
<input type="text" name="ssn" size="20">
<input type="button" value="This returns an invalid if string is all uppercasewhich has to have the 1st letter be uppercase and the rest lowercase"
>
</form>
</body>
</html>
Explanation / Answer
Hi,
Re-reading this post, I'm not sure my prior solution identifies the correct regular expression. If the following names are valid:
ABcdef
GHij
ZZxxx
But these are INVALID:
Abcdef
ghij
ZZXxx
Then the prior regular expression I gave you will need to be changed to:
var RE_SSN = /^[A-Z]{2}[a-z]+$/;
If I'm off-base, be sure to list out some valid vs. invalid inputs as examples and we'll get the right expression to match.
Thanks,
Joe
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.