#include <stdio.h>
#include <string.h>
int main() {
char email[100];
char password[100];
printf("Enter your email: ");
scanf("%s", email);
// ตรวจสอบรูปแบบอีเมล
if (strchr(email, '@') == NULL || strchr(email, '.') == NULL) {
printf("Invalid email format.\n");
}
printf("Enter your password: ");
scanf("%s", password);
// ตรวจสอบความยาวรหัสผ่าน
if (strlen(password) < 8) {
printf("Password must be at least 8 characters long.\n");
}
return 0;
}
import java.util.Scanner;
public class FormValidation {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String email, password;
System.out.print("Enter your email: ");
email = scanner.nextLine();
// ตรวจสอบรูปแบบอีเมล
if (!email.contains("@") || !email.contains(".")) {
System.out.println("Invalid email format.");
}
System.out.print("Enter your password: ");
password = scanner.nextLine();
// ตรวจสอบความยาวรหัสผ่าน
if (password.length() < 8) {
System.out.println("Password must be at least 8 characters long.");
}
scanner.close();
}
}
import re
email = input("Enter your email: ")
password = input("Enter your password: ")
# ตรวจสอบรูปแบบอีเมล
if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
print("Invalid email format.")
# ตรวจสอบความยาวรหัสผ่าน
if len(password) < 8:
print("Password must be at least 8 characters long.")