Monday, August 31, 2009

How to Validate Emain in Java script?

function validateEmail(obj)
{
var fld=0;
var goodEmail = obj.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

fld = obj;

if (goodEmail)
{
good = true
}
else
{
alert("Please enter a valid email address.")
setTimeout("fld.focus();",1);
setTimeout("fld.select();",1);
good = false
}
return good;
}

The above function validates the email.

How to check two decimal validation in java script?

function MoneyValidation()
{
var value1 = document.formaName.fieldName.value;
if(value1.indexOf(".") != -1)
{
if(!/\.[0-9]{1,2}$/.test(value1))
{
alert("value1 should be two fractional positions required");
return false;
}
}

return true;
}

The above function validates up to two decimal positions.
This function allows a value1 with out decimal position.
If there is a decimal point then the field should have at least one number after decimal point the maximum number of digits after the decimal point is two. It wont accept more then two digits after the decimal point.

The indexOf(".") function will return -1 if there is no decimal point the else block will execute that mean true will be return.
If there is a decimal point in value1 then indexOf(".") returns the value >0 according to the didits present before the decimal point. So that it do the validation.

The regular expression validates the number of digits after the decimal point.

Null check function in Javascript.

function checkNullField()

{

var field1 = document.formName.fieldName.value;

if(field1 == '')

{

alert("Field Name is empty");

return false;

}

else

{

return true;

}

}

Once you call this function in your jsp as return checkNullField(); then this function will return false if the field is empty else it will return true.

How to use javacript files in jsp ?

The javascript files are normal text files which have the .js extention.

Once you create the .js file Yiou can extend the .js file into you html or Jsp pages.

< script language="javascript" src="js/demo.js"/ >

The above tag shows the syntax of how to extend the demo.js into your jsp or html page.

js is the folder name and demo.js is the javascript file name.

How do I enable JavaScript in my browser?

To enable java script in you browser, please follow the instructions below:

Internet Explorer (6.0)

1. Select 'Tools' from the top menu
2. Choose 'Internet Options'
3. Click on the 'Security' tab
4. Click on 'Custom Level'
5. Scroll down until you see section labled 'Scripting'
6. Under 'Active Scripting', select 'Enable' and click OK

Netscape Navigator (4.8)

1. Select 'Edit' from the top menu
2. Choose 'Preferences'
3. Choose 'Advanced'
4. Choose 'Scripts & Plugins'
5. Select the 'Enable JavaScript' checkbox and click OK

Mozilla Firefox (1.0)

1. Select 'Tools' from the top menu
2. Choose 'Options'
3. Choose 'Web Features' from the left navigation
4. Select the checkbox next to 'Enable JavaScript' and click OK

Mozilla Firefox (1.5)


1. Select 'Tools' from the top menu
2. Choose 'Options'
3. Choose 'Content' from the top navigation
4. Select the checkbox next to 'Enable JavaScript' and click OK

Apple Safari (1.0)

1. Select 'Safari' from the top menu
2. Choose 'Preferences'
3. Choose 'Security'
4. Select the checkbox next to 'Enable JavaScript'


Please post if any suggessions and any doubts about this.

Sunday, August 9, 2009

Java script basics

Java script is a Programming language which is helpful in developing the client side validations. Using the java script one can develop the forms for the user or validations for the form. It is very helpful for the developer when they are developing web based applications.