0% found this document useful (0 votes)
15 views

CSS Imp Que

The document contains code snippets for: 1. Regular expressions to validate pincodes, mobile numbers, and email addresses. 2. A JavaScript program to validate passwords using a regular expression. 3. Code to output the current date in different formats. 4. Code to output the Fibonacci series for a given limit. 5. Code to check if a string is a palindrome. 6. Code to check if a number is prime. 7. Code to check if a number is an Armstrong number.

Uploaded by

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

CSS Imp Que

The document contains code snippets for: 1. Regular expressions to validate pincodes, mobile numbers, and email addresses. 2. A JavaScript program to validate passwords using a regular expression. 3. Code to output the current date in different formats. 4. Code to output the Fibonacci series for a given limit. 5. Code to check if a string is a palindrome. 6. Code to check if a number is prime. 7. Code to check if a number is an Armstrong number.

Uploaded by

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

Important Points from chapter 5th

1.Regular Expression for Pincode :


Var regex = /^[1-9]{1}[0-9]{2}\\s{0, 1}[0-9]{3}$/;

2.Regular Expression for Mobile No :


var mb =/(0|91)?[6-9][0-9]{9}/;

3.Regular Expression for Email Id :


Var email = / [a-z0-9]+@[a-z]+\.[a-z]{2,3}/;
Javascrpt Program for password Validation:
<html>
<head>
<script type="text/javascript">
function CheckPassword (inputtxt)
{
var passw= /^[A-Za-z]\w{7,14}$/; ### Regular Expression for password
if(inputtxt.value.match(passw))
{
alert('Correct, try another...')
return true;
}
else
{
alert('Wrong...!')
return false;
}
}
</script>
</head>
<body>
<form name="form1" action="#">
<input type='text' name='text1'/>
<input
type="submitvalue="Submit"onclick="CheckPassword(document.form1.text1)"/>

</form>
</body>
</html>

Q1. Write a JavaScript program to get the current date.


Expected Output : mm-dd-yyyy, mm/dd/yyyy or dd-mm-yyyy, dd/mm/yyyy

Ans:

<script>

var today = new Date();

var dd = today.getDate();

var mm = today.getMonth() + 1;

var yyyy = today.getFullYear();

if (dd < 10) {


dd = '0' + dd;
}

if (mm < 10) {


mm = '0' + mm;
}

today = mm + '-' + dd + '-' + yyyy;


console.log(today);

today = mm + '/' + dd + '/' + yyyy;


console.log(today);

today = dd + '-' + mm + '-' + yyyy;


console.log(today);

today = dd + '/' + mm + '/' + yyyy;


console.log(today);
</script>
Fibonancii Series:
<script>
// declaration of the variables
var n1 = 0, n2 = 1, next_num, i;
var num = parseInt (prompt (" Enter the limit for Fibonacci Series "));
document.write( "Fibonacci Series: ");
for ( i = 1; i <= num; i++)
{
document.write (" <br> " + n1);
next_num = n1 + n2;
n1 = n2;
n2 = next_num;
}

</script>
Checking String is Palindrome or not:
<script type="text/javascript">
var string = prompt('Enter a string: ');
function checkPalindrome(string) {
var len = string.length;
for (var i = 0; i < len / 2; i++)
{
if (string[i] !== string[len - 1 - i])
{
alert ('It is not a palindrome');
}
}
alert('It is a palindrome');
}

const value = checkPalindrome(string);


console.log(value);
</script>

Prime No Checking:
<script type="text/javascript">
var number = parseInt(prompt("Enter a positive number: "));
let isPrime = true;

if (number === 1) {
console.log("1 is neither prime nor composite number.");
}

else if (number > 1) {

for (let i = 2; i < number; i++) {


if (number % i == 0) {
isPrime = false;
break;
}
}

if (isPrime) {
alert("{number} is a prime number");
} else {
alert("{number} is a not prime number");
}
}

else {
console.log("The number is not a prime number.");
}

Checking Armstrong No:


let sum = 0;
const number = prompt('Enter a three-digit positive integer: ');

let temp = number;


while (temp > 0) {

let remainder = temp % 10;

sum += remainder * remainder * remainder;

temp = parseInt(temp / 10);


}

if (sum == number) {
alert(" is an Armstrong number");
}
else {
alert(" is not an Armstrong number");
}

Armstrong No Logic: ex: 153=(1*1*1+5*5*5+3*3*3) addition of each no cube is


equal to that given is known as Armstrong no

You might also like