0% found this document useful (0 votes)
12 views4 pages

Pending It PRC

The document contains two sections: one for a JavaScript form validation and another for a PHP vowel counting function. The JavaScript section specifies required fields, input patterns for email and telephone, and hints for the address field. The PHP section includes a form to input a string and a function to count and display the number of vowels in that string.

Uploaded by

aksh5513
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Pending It PRC

The document contains two sections: one for a JavaScript form validation and another for a PHP vowel counting function. The JavaScript section specifies required fields, input patterns for email and telephone, and hints for the address field. The PHP section includes a form to input a string and a function to count and display the number of vowels in that string.

Uploaded by

aksh5513
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

JavaScript

Sop 2
Create JavaScript program for the following form validations. Make use of
HTML5 properties to do the following validations :

1) Name, address, contact number and email are required fields of the form.

2) Address field should show the hint value which will disappear when field
gets focus or key press event.

3) Telephone number should be maximum 10 digit number only.

4) Email field should contain valid email address, @ should appear only once
and not at the beginning or at end. It must contain at least one dot(.).

5) Make use of pattern attribute for email to accept lowercase, uppercase


alphabets, digits and specified symbols.

<!DOCTYPE html>

<html>

<head>

<title>Information From</title>

</head>

<body>

<form>

<h1 align="left">Information From</h1><br>

Your Name:<input type="text" required/><br>

Address:<input type="text" placeholder="Permanent Address" required/><br>

Contact:<input type="tel" pattern="[0-9] {2} -[0-9] {10}" required/><br>


E-mail:<input type="email" pattern="[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-
Z]{2,}" required/><br>

<input type="submit" value="Submit"/>

</form>

</body>

</html>
PHP
Sop 2
Write a PHP function to count the total number of vowels
(a,e,i,o,u) from the string. Accept a string by using HTML
form.

<!DOCTYPE html>

<html>

<head>

<title>Vowel Counter</title>

</head>

<body>

<h2>Count Vowels in a String</h2>

<form method="post" action="">

<label for="inputString">Enter a string:</label>

<br>

<input type="text" id="inputString" name="inputString" required>

<br><br>

<button type="submit" name="submit">Count Vowels</button>

</form>

<?php

if (isset($_POST['submit'])) {
$inputString = $_POST['inputString'];

$vowelCount = countVowels($inputString);

echo "<h3>The total number of vowels in the string is: $vowelCount</h3>";

function countVowels($str) {

$vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];

$count = 0;

for ($i = 0; $i < strlen($str); $i++) {

if (in_array($str[$i], $vowels)) {

$count++;

return $count;

?>

</body>

</html>

You might also like