<script type="text/javascript">

//** Ignore enter key

$(document).ready(function() {
  $('#goodform').keydown(function(event){
     if(event.keyCode == 13) {
       event.preventDefault();
       return false;
     }
   });
});

function validate()
{
var MyString1 = document.getElementById('first2').value;
var MyString2 = document.getElementById('last2').value;
var MyString3 = document.getElementById('user2').value;
var MyString4 = document.getElementById('phone2').value;

// Check for blank entries

if(MyString1 == "" )
{
   alert("Please enter your first name");
   return false;
}
if(MyString2 == "" )
{
   alert("Please enter your last name");
   return false;
}
if(MyString3 == "" || MyString3.length < 6)
{
   alert("Please enter a user name of at least six characters");
   return false;
}
if(MyString4 == "" || MyString4.length < 10)
{
   alert("Please enter your phone number with area code.");
   return false;
}

// Validate user input

valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; //** Useable characters;
for (var i=0; i<MyString1.length; i++) {
  if (valid.indexOf(MyString1.charAt(i)) < 0) {
    alert('Your first name contains invalid characters');
     return false;
} }

valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; //** Useable characters;
for (var i=0; i<MyString2.length; i++) {
   if (valid.indexOf(MyString2.charAt(i)) < 0) {
     alert('Your last name contains invalid characters');
     return false;
} }

valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; //** Useable characters;
for (var i=0; i<MyString3.length; i++) {
   if (valid.indexOf(MyString3.charAt(i)) < 0) {
     alert('Your username contains invalid characters');
     return false;
} }

valid="0123456789- "; //** Useable characters;
for (var i=0; i<MyString4.length; i++) {
   if (valid.indexOf(MyString4.charAt(i)) < 0) {
     alert('Your phone number contains invalid characters');
     return false; } }

   var pattern = /-/g;         //** Replace dash with nothing
   var MyNewString4=MyString4.replace(pattern, "");
   document.getElementById('phone2').value = MyNewString4;


   var pattern = / /g;         //** Replace space with nothing
   var MyNewString4=MyString4.replace(pattern, "");
   document.getElementById('phone2').value = MyNewString4;
}
</script>