SOP 2. Write a java script program for the following form validations using HTML5 properties.
<html>
<head>
<title>Form validation</title>
<script>
function validate() { var name =
document.forms.RegForm.Name.value;
var email =document.forms.RegForm.EMail.value;
var phone =document.forms.RegForm.Mobile.value;
var regEmail=/^\w+([\.-]?\w+)@\w+([\.-]?\w+)(\.\w{2,3})+$/g;
var regName = /\d+$/g;
if (name == "" || regName.test(name)) { window.alert("Please enter your name properly."); name.focus();
return false;
}
if (email == "" || !regEmail.test(email)) { window.alert("Please enter a valid e-mail address."); email.focus();
return false;
}
if (phone == "" || !regPhone.test(phone)) { alert("Please enter valid phone number."); phone.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<h1>REGISTRATION FORM</h1>
<form name="RegForm" onsubmit="return validate()" method="post">
<table>
<tr>
<th>Name: </th>
<td><input type="text" name="Name"></td>
</tr>
<tr>
<th>E-mail Address:</th>
<td> <input type="text" name="EMail"></td>
</tr>
<tr>
<th>Mobile: </th>
<td><input type="text" name="Mobile"></td>
</tr>
<tr>
<td><input type="submit" value="send" name="Submit"onclick="validate()">
<input type="reset" value="Reset" name="Reset"></td>
</tr>
</form>
</body>
</html>
SOP 3 Create JavaScript program For Count no vowels in String.
<html>
<head>
<title>Count no of vowels</title>
</head>
<body>
<script type="text/javascript">
function countVowel(str) {
const count = str.match(/[aeiou]/gi).length;
return count;
}
const string = prompt('Enter a string: ');
const result = countVowel(string);
alert("No of vowels"+result);
</script>
</body>
</html>
SOP 4 Create JavaScript Program check whether String is Palindrome or not.
<html>
<head>
<title>Palindrome Program </title>
</head>
<body>
<script>
function checkPalindrome(string)
{
const len = string.length;
for (let i = 0; i < len / 2; i++)
{
if (string[i] !== string[len - 1 - i])
{
alert("It is not Palindrome");
}
else
{
alert("It is Palindrome");
}
const string = prompt('Enter a string: ');
const value = checkPalindrome(string);
</script>
</body>
</html>
SOP 5 Create JavaScript Program for temperature conversion.
<html>
<head>
<title>Temp conversion program</title>
</head>
<body>
<script type="text/javascript">
let celsius = prompt("Enter temperature in Celsius: ");
let fahrenheit = (celsius * 9/5) + 32;
alert(`The temperature in Fahrenheit is ${fahrenheit.toFixed(2)}`);
</script>
</body>
</html>