CodeSolved

A comprehensive source of programming questions and exercises

Form validation with JavaScript

Practice Easy 965/ Download 426 Views

Create a form to get the following from the user and to validate this form

Name and last name (up to 2 characters)
Age (between 1 and 2)
E -mail (in email format)
Mobile number (starting with 1 and 2 digits)
Password (at least 2 characters, including #, numbers and uppercase and lowercase letters)

1 Answers

<!DOCTYPE html>
<html lang="fa">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>فرم ثبت‌نام</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container">
        <h1>فرم ثبت‌نام</h1>
        <form id="registrationForm">
            <label for="fullName">نام و نام خانوادگی:</label>
            <input type="text" id="fullName" name="fullName" maxlength="50" required>

            <label for="age">سن:</label>
            <input type="number" id="age" name="age" min="18" max="70" required>

            <label for="email">ایمیل:</label>
            <input type="email" id="email" name="email" required>

            <label for="phone">شماره موبایل:</label>
            <input type="text" id="phone" name="phone" pattern="^09\d{9}$" required>

            <label for="password">رمزعبور:</label>
            <input type="password" id="password" name="password" required>

            <button type="submit">ثبت‌نام</button>
        </form>
        <div id="message" class="message"></div>
    </div>
    <script src="script.js"></script>
</body>
</html>
Mma123 Download HTML & CSS

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close