Reputation:
I have a code here and now I want to add regular expressions to it. On the "Bedrijfsnaam" it needs to be accepted to use alphabetic characters, numbers, spaces and a few symbols like: . - _ and @. On the "Contactpersoon" it only needs to be accepted to use alphabetic characters, spaces and dots. For the "Email" it needs to be accepted to use alphabetic characters and a ., followed by a @, then alphabetic characters and a -, a . and after that a maximum of 3 alphabetic characters //This is because i also want this email adresses to be able: [email protected] or [email protected]
on "Telefoonnummer" it only needs to be accepted to use 10 digits.
This is the javascript code I allready have:
<script language="JavaScript" type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["Bedrijfsnaam"].value;
if (x==null || x=="")
{
alert("De bedrijfsnaam is niet ingevuld, u wordt verzocht dit veld in te vullen.");
return false;
}
var x=document.forms["myForm"]["Contactpersoon"].value;
if (x==null || x=="")
{
alert("De naam van de contactpersoon is niet ingevuld, u wordt verzocht dit veld in te vullen.");
return false;
}
var x=document.forms["myForm"]["Email"].value;
if (x==null || x=="")
{
alert("Het E-mailadres van de contactpersoon is niet ingevuld, u wordt verzocht dit veld in te vullen.");
return false;
}
var x=document.forms["myForm"]["Telefoonnummer"].value;
if (x==null || x=="")
{
alert("Het telefoonnummer van de contactpersoon is niet ingevuld, u wordt verzocht dit veld in te vullen.");
return false;
}
var x=document.forms["myForm"]["option1"].value;
if (x==null || x=="")
{
alert("Zoekwoordcombinatie 1 van de gewenste zoekwoordcombinaties waarop uw bedrijf online vindbaar wil zijn is niet ingevuld, u wordt verzocht dit veld in te vullen.");
return false;
}
}
</script>
Upvotes: 3
Views: 168
Reputation: 447
RegExpes are absolutely the way to go. You should do some more research on them though, people are busy with their own work you know :-)
Learning RegExes are a lot easier with an interactive interpreter. There are tons on the internet, here is one random one : http://regexpal.com/
Upvotes: 0
Reputation: 13544
You will find a useful library for regular expressions at the following website: http://regexlib.com/
Upvotes: 1