Can someone help with this java

Hi all iv been posting here for a few weeks now getting help and you guys have been great, well heres whats up iv had to type up a Orderform in javascript my problem is i cant work out how to make number and letter only areas :frowning: can anyone gave me a line of code? heres what iv made so far, if possible add the line of code onto mine so i can see how she goes together :slight_smile: thanks all

<html>
<head>
<title>Joe's Fruit Shop Order Form</title>
<script language="javascript" type="text/javascript"> 
 
<!-- hide script from older browsers
function validateForm(contact)
{
 
if(document.forms.contact.fullName.value=="")
{
alert("Please enter your full name.");
document.forms.contact.fullName.focus();
return false;
}
 
if(document.forms.contact.homephone.value=="")
{
alert("Please enter your phone number.");
document.forms.contact.homephone.focus();
return false;
}
 
if(document.forms.contact.email.value=="")
{
alert("Please enter your email address.");
document.forms.contact.email.focus();
return false;
}
 
if(document.forms.contact.address.value=="")
{
alert("Please enter your address.");
document.forms.contact.address.focus();
return false;
}
 
if(document.forms.contact.citysuburb.value=="")
{
alert("Please enter your city\\suburb.");
document.forms.contact.citysuburb.focus();
return false;
}
 
if(document.forms.contact.state.value=="")
{
alert("Please select your state.");
document.forms.contact.state.focus();
return false;
}
 
if(document.forms.contact.postcode.value=="")
{
alert("Please enter your post code.");
document.forms.contact.postcode.focus();
return false;
}
 
if(document.forms.contact.cardtype.value=="")
{
alert("Please select card Type.");
document.forms.contact.cardtype.focus();
return false;
}
 
if(document.forms.contact.month.value=="")
{
alert("Please select your Card Expiry Month.");
document.forms.contact.month.focus();
return false;
}
 
if(document.forms.contact.year.value=="")
{
alert("Please select your Card Expiry Year.");
document.forms.contact.year.focus();
return false;
}
 
if(document.forms.contact.cardnumber.value=="")
{
alert("Please enter your Card Number.");
document.forms.contact.cardnumber.focus();
return false;
}
 
if(document.forms.contact.cardholder.value=="")
{
alert("Please enter the Card Holder's Name.");
document.forms.contact.cardholder.focus();
return false;
}
 
if(document.forms.contact.item1.value=="")
{
alert("Please select an Item you must make at least 1 selection.");
document.forms.contact.item1.focus();
return false;
}
 
if(document.forms.contact.quantity1.value=="")
{
alert("Please select the quantity of the item you would like you must make at least 1 selection.");
document.forms.contact.quantity1.focus();
return false;
}
 
if(document.forms.contact.item2.value=="")
{
alert("Please select an Item.");
document.forms.contact.item2.focus();
return false;
}
 
if(document.forms.contact.quantity2.value=="")
{
alert("Please select the quantity of the item you would like.");
document.forms.contact.quantity2.focus();
return false;
}
 
if(document.forms.contact.item3.value=="")
{
alert("Please select an Item.");
document.forms.contact.item3.focus();
return false;
}
 
if(document.forms.contact.quantity3.value=="")
{
alert("Please select the quantity of the item you would like.");
document.forms.contact.quantity3.focus();
return false;
}
 
if(document.forms.contact.item4.value=="")
{
alert("Please select an Item.");
document.forms.contact.item4.focus();
return false;
}
 
if(document.forms.contact.quantity4.value=="")
{
alert("Please select the quantity of the item you would like.");
document.forms.contact.quantity4.focus();
return false;
}
 
if(document.forms.contact.item5.value=="")
{
alert("Please select an Item.");
document.forms.contact.item5.focus();
return false;
}
 
if(document.forms.contact.quantity5.value=="")
{
alert("Please select the quantity of the item you would like.");
document.forms.contact.quantity5.focus();
return false;
}
 
}
stop hiding script -->
</script>
 
</head> 
<body>
<h2>Joe's Fruit Shop Order Form</h2> <p>Your details and delivery address: Regions that contain a "*" are required</p>
 
<form name="contact" method="post" action="" onSubmit="return validateForm(contact);">
 
<table border="1">
 
<tr>
<td>*Full Name:</td>
<td><input type="text" name="fullName" length="25"></td>
<td>*Home Phone:</td>
<td><input type="text" name="homephone" length="25"></td> 
</tr>
 
<tr>
<td>Mobile Phone:</td>
<td><input type="text" name="mobilephone" length="25"></td> 
<td>Work Phone:</td>
<td><input type="text" name="workphone" length="25"></td> 
</tr>
 
<tr>
<td>*E-Mail:</td>
<td><input type="text" name="email" length="25"></td> 
<td>*Address:</td>
<td><input type="text" name="address" length="25"></td> 
</tr>
 
<tr>
<td>*City Suburb:</td>
<td><input type="text" name="citysuburb" length="25"></td> 
<td>*State:</td>
<td>
<SELECT name="state"> 
<OPTION SELECTED value="">State
<OPTION value="1">QLD
<OPTION value="2">NSW
<OPTION value="3">ACT
<OPTION value="4">VIC
<OPTION value="5">TAS
<OPTION value="6">SA
<OPTION value="7">NT
<OPTION value="8">WA
</SELECT>
</td>
</tr>
<tr>
<td>*Post Code:</td>
<td><input type="text" name="postcode" length="25"></td> 
</tr>
</table> 
 
<hr>
<p>*Credit card details:</p>
 
<table border="1">
<tr>
<td>*Card Type</td>
<td>
<select name="cardtype">
            <option>Please select card type</option>
            <option value="1">Visa</option>
            <option value="2">Master Card</option>
            <option value="3">AMX</option>
          </select>
</td>
<td>*Expiry date:</td>
<td>
<select name="month">
          <OPTION SELECTED value="">Month
          <option value="1">Jan
          <option value="2">Fab
          <option value="3">Mar
          <option value="4">Apr
          <option value="5">May
          <option value="6">Jun
          <option value="7">Jul
          <option value="8">Aug
          <option value="9">Sep
          <option value="10">Oct
          <option value="11">Nov
          <option value="12">Dec
        </select>
<select name="year">
  <OPTION SELECTED value="">Year
  <option value="1">2009
  <option value="2">2010
  <option value="3">2011
  <option value="4">2012
  <option value="5">2013
</select>
</td>
</tr>
 
<tr>
<td>*Card Number:</td>
<td><input type="text" name="cardnumber" length="25"></td> 
<td>*Card holder's name:</td>
<td><input type="text" name="cardholder" length="25"></td>
</tr>
</table>
 
<hr>
<p>*Purchase details:</p>
 
<table border="1">
<tr><td>*Item choises and Quantity.</td></tr>
<tr><td>
<select name="item1">
            <OPTION SELECTED value="">Item
            <option value="1">Alfalfa sprouts $1.50 per punnet
            <option value="2">Apples, Bonza $5.99KG
            <option value="3">Apples, Golden Delicious $4.99KG
            <option value="4">Artichoke hearts, pickled $17.99KG
            <option value="5">Avocados, dark, large 2 for $3.50
          </select>
 <select name="quantity1">
            <OPTION SELECTED value="">Quantity
            <option value="1">1
            <option value="2">2
            <option value="3">3
            <option value="4">4
            <option value="5">5
            <option value="6">6
            <option value="7">7
            <option value="8">8
            <option value="9">9
            <option value="10">10
          </select>
</tr></td>
 
<tr><td>
<select name="item2">
            <OPTION SELECTED value="0">Item
            <option value="1">Alfalfa sprouts $1.50 per punnet
            <option value="2">Apples, Bonza $5.99KG
            <option value="3">Apples, Golden Delicious $4.99KG
            <option value="4">Artichoke hearts, pickled $17.99KG
            <option value="5">Avocados, dark, large 2 for $3.50
          </select>
 <select name="quantity2">
            <OPTION SELECTED value="0">Quantity
            <option value="1">1
            <option value="2">2
            <option value="3">3
            <option value="4">4
            <option value="5">5
            <option value="6">6
            <option value="7">7
            <option value="8">8
            <option value="9">9
            <option value="10">10
          </select>
</tr></td>
 
<tr><td>
<select name="item3">
            <OPTION SELECTED value="0">Item
            <option value="1">Alfalfa sprouts $1.50 per punnet
            <option value="2">Apples, Bonza $5.99KG
            <option value="3">Apples, Golden Delicious $4.99KG
            <option value="4">Artichoke hearts, pickled $17.99KG
            <option value="5">Avocados, dark, large 2 for $3.50
          </select>
 <select name="quantity3">
            <OPTION SELECTED value="0">Quantity
            <option value="1">1
            <option value="2">2
            <option value="3">3
            <option value="4">4
            <option value="5">5
            <option value="6">6
            <option value="7">7
            <option value="8">8
            <option value="9">9
            <option value="10">10
          </select>
</tr></td>
 
<tr><td>
<select name="item4">
            <OPTION SELECTED value="0">Item
            <option value="1">Alfalfa sprouts $1.50 per punnet
            <option value="2">Apples, Bonza $5.99KG
            <option value="3">Apples, Golden Delicious $4.99KG
            <option value="4">Artichoke hearts, pickled $17.99KG
            <option value="5">Avocados, dark, large 2 for $3.50
          </select>
 <select name="quantity4">
            <OPTION SELECTED value="0">Quantity
            <option value="1">1
            <option value="2">2
            <option value="3">3
            <option value="4">4
            <option value="5">5
            <option value="6">6
            <option value="7">7
            <option value="8">8
            <option value="9">9
            <option value="10">10
          </select>
</tr></td>
 
<tr><td>
<select name="item5">
            <OPTION SELECTED value="0">Item
            <option value="1">Alfalfa sprouts $1.50 per punnet
            <option value="2">Apples, Bonza $5.99KG
            <option value="3">Apples, Golden Delicious $4.99KG
            <option value="4">Artichoke hearts, pickled $17.99KG
            <option value="5">Avocados, dark, large 2 for $3.50
          </select>
 <select name="quantity5">
            <OPTION SELECTED value="0">Quantity
            <option value="1">1
            <option value="2">2
            <option value="3">3
            <option value="4">4
            <option value="5">5
            <option value="6">6
            <option value="7">7
            <option value="8">8
            <option value="9">9
            <option value="10">10
          </select>
</tr></td>
</table>
 
<table> 
<tr><td>Click <b>Submit</b> to submit the order form, click <b>Reset</b> to reset the form.</td></tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit">
</td>
<td><input type="reset" name="reset"></td>
</tr>
 </table>
</form>
</body>
</html>

do you think id be able to add this into the code i have alredy created or will i need to fully replace my number and letter areas with this code?. if i can join my code and this code together is there any chance your could give me an example on how to lol soz bout asking so much im very very new to java im only used to CSS HTML and XHTML lolz

This is a script i found that works great

HTML: Numbers only

<input type="text" id="input1" onkeypress="return restrictCharacters(this, event, digitsOnly);" />

HTML: Letters only

<input type="text"  id="input1" onkeypress="return restrictCharacters(this, event, alphaOnly);" />

Javascript:

/* code from qodo.co.uk */
// create as many regular expressions here as you need:
var digitsOnly = /[1234567890]/g;
var alphaOnly = /[a-zA-Z]/g;

function restrictCharacters(myfield, e, restrictionType){
    if (!e) var e = window.event
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    var character = String.fromCharCode(code);

    // if they pressed esc... remove focus from field...
    if (code == 27){ 
        this.blur();
        return false;
    }
    
    // ignore if they are press other keys
    // strange because code: 39 is the down key AND ' key...
    // and DEL also equals .
    if (!e.ctrlKey && code!=9 && code!=8 && code!=36 && code!=37 && code!=38 && (code!=39 || (code==39 && character=="'")) && code!=40){
        if (character.match(restrictionType)){
            return true;
        } else {
            return false;
        }
    }
}