Practice 50 JavaScript Validation without Regular expression Programming Questions
Q1. Write a JavaScript program to check if a number is a positive integer.
Input: 5
Expected Output: true
Q2. Write a JavaScript program to check if a string is a valid email address.
Input: "user@example.com"
Expected Output: true
Q3. Write a JavaScript program to check if a number is an integer.
Input: 4.5
Expected Output: false
Q4. Write a JavaScript program to check if a string contains only alphabets.
Input: "HelloWorld"
Expected Output: true
Q5. Write a JavaScript program to check if a string is a valid phone number (should be 10 digits).
Input: "1234567890"
Expected Output: true
Q6. Write a JavaScript program to check if a number is a valid positive float.
Input: 12.45
Expected Output: true
Q7. Write a JavaScript program to check if a string is a valid URL.
Input: "https://www.example.com"
Expected Output: true
Q8. Write a JavaScript program to check if a password is valid (at least 8 characters, includes numbers and letters).
Input: "password123"
Expected Output: true
Q9. Write a JavaScript program to check if a given string has only numbers.
Input: "123456"
Expected Output: true
Q10. Write a JavaScript program to check if a string contains a valid date format (MM/DD/YYYY).
Input: "12/31/2023"
Expected Output: true
Q11. Write a JavaScript program to check if a string is a valid ZIP code (5 digits).
Input: "12345"
Expected Output: true
Q12. Write a JavaScript program to validate if a string is in a valid 24-hour time format (HH:MM).
Input: "14:30"
Expected Output: true
Q13. Write a JavaScript program to check if a string is a valid credit card number (16 digits).
Input: "1234567890123456"
Expected Output: true
Q14. Write a JavaScript program to validate if a string starts with a specific letter.
Input: "Hello"
Expected Output: true
Q15. Write a JavaScript program to validate if a number is even.
Input: 4
Expected Output: true
Q16. Write a JavaScript program to validate if a number is odd.
Input: 5
Expected Output: true
Q17. Write a JavaScript program to validate if a number is greater than a given number.
Input: 6, 5
Expected Output: true
Q18. Write a JavaScript program to check if a string is a valid time in the 12-hour format (hh:mm AM/PM).
Input: "12:30 PM"
Expected Output: true
Q19. Write a JavaScript program to check if a string is a valid social security number (SSN).
Input: "123-45-6789"
Expected Output: true
Q20. Write a JavaScript program to check if a string is a valid hex color code (starting with # followed by 6 hexadecimal characters).
Input: "#a1b2c3"
Expected Output: true
Q21. Write a JavaScript program to validate if a string is in uppercase.
Input: "HELLO"
Expected Output: true
Q22. Write a JavaScript program to check if a string is in lowercase.
Input: "hello"
Expected Output: true
Q23. Write a JavaScript program to check if a string contains only alphanumeric characters.
Input: "abc123"
Expected Output: true
Q24. Write a JavaScript program to validate if a string is a valid hexadecimal number.
Input: "a1f3b7"
Expected Output: true
Q25. Write a JavaScript program to check if a string matches the YYYY-MM-DD date format.
Input: "2023-12-31"
Expected Output: true
Q26. Write a JavaScript program to check if a string matches the DD/MM/YYYY date format.
Input: "31/12/2023"
Expected Output: true
Q27. Write a JavaScript program to check if a string contains only spaces.
Input: " "
Expected Output: true
Q28. Write a JavaScript program to check if a string contains only digits.
Input: "012345"
Expected Output: true
Q29. Write a JavaScript program to check if a string is a valid IPv4 address.
Input: "192.168.1.1"
Expected Output: true
Q30. Write a JavaScript program to check if a string is a valid hexadecimal color code without the #.
Input: "a1b2c3"
Expected Output: true
Q31. Write a JavaScript program to validate if a string contains only vowels.
Input: "aeiou"
Expected Output: true
Q32. Write a JavaScript program to check if a string contains no vowels.
Input: "bcdfg"
Expected Output: true
Q33. Write a JavaScript program to check if a string is a valid date in YYYY/MM/DD format.
Input: "2023/12/31"
Expected Output: true
Q34. Write a JavaScript program to check if a string is a valid phone number (with or without dashes).
Input: "123-456-7890"
Expected Output: true
Q35. Write a JavaScript program to check if a string contains only numbers and spaces.
Input: "123 456 789"
Expected Output: true
Q36. Write a JavaScript program to check if a string contains only letters and numbers.
Input: "abc123XYZ"
Expected Output: true
Q37. Write a JavaScript program to check if a number is a prime number.
Input: 7
Expected Output: true
Q38. Write a JavaScript program to validate if a string is a valid binary number.
Input: "110101"
Expected Output: true
Q39. Write a JavaScript program to check if a number is divisible by 3.
Input: 9
Expected Output: true
Q40. Write a JavaScript program to validate if a string is a valid floating-point number.
Input: "12.34"
Expected Output: true
Q41. Write a JavaScript program to check if a number is within a given range (inclusive).
Input: 10, 5, 15
Expected Output: true
Q42. Write a JavaScript program to check if a number is greater than zero.
Input: 5
Expected Output: true
Q43. Write a JavaScript program to validate if a string is a valid time in the HH:MM:SS format.
Input: "14:30:45"
Expected Output: true
Q44. Write a JavaScript program to check if a string is a valid file extension (.txt, .jpg, etc.).
Input: "image.jpg"
Expected Output: true
Q45. Write a JavaScript program to check if a string is a valid domain name.
Input: "example.com"
Expected Output: true
Q46. Write a JavaScript program to validate a year (greater than or equal to 1900).
Input: "2023"
Expected Output: true
Q47. Write a JavaScript program to check if a number is a perfect square.
Input: 16
Expected Output: true
Q48. Write a JavaScript program to check if a string contains only punctuation characters.
Input: ".!?"
Expected Output: true
Q49. Write a JavaScript program to check if a string is a valid month name (e.g., "January").
Input: "March"
Expected Output: true
Q50. Write a JavaScript program to validate a string to check if it matches a proper file path format.
Input: "C:\\Users\\John\\Documents\\file.txt"
Expected Output: true
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!