You are on page 1of 5

Practical no -12

develop web page for validation of form fields using regular expression.

<html>

<head>

<script type="text/javascript">

function TestString(str)

re=/[az]/;

if(re.test(str))

alert("the letter a or z both are present in the string");

else{

alert("string does not contain a or z or both");

</script>

<h2>Example of regular expression</h2>

<script type="text/javascript">

var input_str=prompt("enter some string here...","");

TestString(input_str);

</script>

</html>
Output-
program no -2

<html>

<head>

<script type="text/javascript">

function TestString(input_str){

re=/[^0-9]/;

if(re.test(input_str))

alert("the string does not contain any digit");

else{

alert("string contains some digit(s)");

</script>

</head>

<body>

<h2>Example of regular expression</h2>

<script type="text/javascript">

var input_str=prompt("enter some input...","");

TestString(input_str);

</script>

</body>

</html>
Output-

program no-3

<html>

<title>Pattern matching using regular expression</title>

<script type="text/javascript">

function TestString(str){

document.write("the given string is:");

document.write("<em>"+str+"</em>"+"<br/>");

var i=str.match(/[1234][A-Z]{2}\d{2}[A-Z]{2}\d{3}/);

if(i==null)
return false;

else

return true;}

<h3>

<script type="text/javascript">

var input_str=prompt("enter your university seat number here","");

if(TestString(input_str))

document.write("valid seat no");

elsedocument.write("invalid seat number");

</script>

</h3>

</html>

Output-

You might also like