Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Lab 4</title>
- </head>
- <body>
- <script type="text/javascript">
- function isPhoneNumValid(str) {
- var regex = new RegExp("8\-[0-9]{3}\-[0-9]{4}\-[0-9]{4}$");
- return regex.test(str);
- }
- function ifName(str) {
- var regex = new RegExp("^[A-Z]{1}\[a-z]+$");
- return regex.test(str);
- }
- function CheckData() {
- var ans = confirm("Вы уверены, что хотите отправить введенные данные ?");
- var ph = document.getElementById("phone").value;
- var phh = document.getElementById("Name").value;
- if (ans && !isPhoneNumValid(ph) && !ifName(phh)) {
- document.getElementById("error").innerHTML = "WRONG NUMBER FORMAT";
- return false;
- }
- else if (ans) {
- document.getElementById("success").innerHTML = "SUCCESS!";
- }
- return false;
- }
- </script>
- <h1 id="error" style="color: #FF0000";></h1>
- <h1 id="success" style="color: #00FF00";></h1>
- <form action="#" onsubmit="return CheckData();">
- <p>Phone (8-***-****-****):</p><input name="phone" id="phone" type="text" />
- <p>Name:</p><input name="Name" id="Name" type="text" />
- <input type="submit" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement