<html>
<head>
</head>
<body>
<input type="input" id="mytext">
<br>
<input type="button" onclick="generate()" value="проверить идентификатор">
<script>
function isLetter(str) {
return str.match(/[a-zA-Z0-9]/i);
}
function generate(){
let elem = document.getElementById("mytext");
let txt = elem.value;
let found = 0;
for (let i = 0;i < 10;i++){
if (txt[0] == i ) found = 1;
}
let found_2 = 0;
for (let i = 0; i < txt.length;i++){
if (isLetter(txt[i]) != null){
found_2 = 1;
}
else{
found_2 = 2;
}
}
if (found == 1){
alert("Идентификатор не должен начинаться с цифры");
}
if (found_2 == 1 && found == 0){
alert("Идентификатор прошел простую проверку");
}
}
</script>
</body>
</html>
|