Username:   Password:  

Verify email address with Javascript

function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	}
	return false;
}

Verifies, if input is a valid email address with Javascript by using regular expressions

Tags

regex email verify verification address JS Javascript

Getting the value of multiple selected options

var foo = [];  
$('#multiple :selected').each(function(i, selected){
  foo[i] = $(selected).text();
});
// to get the selected values, just use .val() - this returns a string or array
foo = $('#multiple :selected').val();  

We’re using jQuery’s “each()” method to loop through all selected options in a multiple select list. Each value or text value is read into an array for later use.

Tags

jQuery javascript input select form

Access iPhone GPS with Javascript

navigator.geolocation.getCurrentPosition(success, fail);
 
// success callback, gets passed position object
success(position) {
	alert(
		"Your latitude: " + position.coords.latitude +
		"longitude: " + position.coords.longitude);
}

Javascript code for accessing the iPhone 3.0 GPS in Safari.

Tags

iPhone iPod GPS 3.0 firmware location JS Javascript

Test if browser is Internet Explorer in Javascript

function isIE {
	var name = 'MSIE';
 
	var agent = navigator.userAgent.toLowerCase();  
 
	return (agent.indexOf(name.toLowerCase()) > - 1);
}

This function tests, if the browser that is viewing the site, is some version of the internet explorer

Tags

internet explorer javascript user agent

Get the value of a selected option with jQuery

$('#selectList').val();

Tags

jQuery javascript input

Test if string is alphanumeric in Javascript

function isAlphaNum(alphane) {
	var numaric = alphane;
 
	for(var j=0; j<numaric.length; j++) {
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
 
		if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123)) {
		} else {
			return false;
		}
		}
	return true;
}

This Javascript function tests, if a given string consists only of alphanumeric characters.

Tags

Javascript test alphanumeric

jQuery Ajax example

$(document).ready(function() {
	$("#link").click(function() {
		$("#output").load(
						"site.php",
						{ id: 4, name: "test" },
						function() {
							alert("I was clicked");
						}
		);
	});
});

Loads page "site.php" with passed post variables "id" & "name" and posts the output to div "output", when DOM element with id "link" is clicked

Tags

jQuery Javascript Ajax

Get clipboard content with Javascript

<script language="JavaScript">
<!--
  contents = clipboardData.getData("Text");
  document.write(contents);
//-->
</script>

Gets the clipboard contents, if the clipboard contains text

Tags

JS Javascript clipboard

Set multiple HTML attributes with jQuery

$("#myimg").attr({
	src : "myimage.gif",
	title : "My Image",
	alt : "My Image",
	border : 0
});

Tags

jQuery Javascript