A Guide to Mobile and Web Technology(LAMP)

Posts tagged ‘email’

Email Validation using Php and Javascript

This function checks whether the email provided is valid and returns false if not valid.

Php Function for validating email

//$email -> email value to be validated.

function callEmailCheck($email, $strict = false)
{
$regex = $strict? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$¦\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' ;
if (preg_match($regex, trim($email), $matches))    {
return array($matches[1], $matches[2]);
}
else {
return false;
}
}

This function checks whether the user email entered in the text box is valid or not. Call this function on submit.

Javascript Function for validating email

function callEmailCheck() {
var emailreg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//useremail is the name of the email text field.
var email = document.getElementById("useremail").value;
if(emailreg.test(email) == true){
return email;
}
return "";
}

How to send a Email attachment or MMS in Android

The following lines of code are used to send a image as either mail attachment
or as MMS from the android mobile programatcally!


Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("image/jpeg");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Picture");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/test.png"));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Email:"));