/    Sign up×
Community /Pin to ProfileBookmark

MAC address validation — simple format

I just want to make sure that they enter the MAC address in this form..

00:01:20:A6:98:B0

he is the validation code that I have

[CODE]else if(document.form2.mac.value.search(/d{2}:d{2}:d{2}:d{2}:d{2}:d{2}/)==-1)
{
alert(“Enter the MAC address using the following form:rn00:01:20:A6:98:B0”);
}[/CODE]

even when I enter in the correct format it throws the alert.. what am I doing wrong.. it is being read in as text.. the phone one works.. so I was tring to do it like that

here is the full validation code in case you want to see it..

[CODE]function validateForm() {
if( document.getElementById(‘FirstName’).value == “” ||
document.getElementById(‘LastName’).value == “” ||
//document.getElementById(‘Site’).value == “” ||
document.getElementById(‘Building’).value == “” ||
document.getElementById(‘StudentRoom’).value == “” ||
document.getElementById(‘Phone’).value == “” ||
document.getElementById(’email’).value == “” ||
document.getElementById(‘ipaddress’).value == “” ||
document.getElementById(‘mac’).value == “” ||
document.getElementById(‘Problem’).value ==””)
{
alert(“Please fill in all fields.”);
}
else if(document.getElementById(’email’).value.indexOf(“@”) == -1 || document.getElementById(’email’).value.indexOf(“.”) == -1)
{
alert(“Your E-mail address is not in the correct format.”);
}
else if(document.getElementById(’email’).value.indexOf(” “) > 0)
{
alert(“Your E-mail address cannot contain spaces.”);
}
else if(document.form2.Phone.value.search(/d{3}-d{3}-d{4}/)==-1)
{
alert(“The phone number you entered is not valid.rnPlease enter a phone number with the format xxx-xxx-xxxx.”);
}
else if(document.form2.mac.value.search(/d{2}:d{2}:d{2}:d{2}:d{2}:d{2}/)==-1)
{
alert(“Enter the MAC address using the following form:rn00:01:20:A6:98:B0”);
}
else
{
return true;
}
return false;
} [/CODE]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@LogicianAug 21.2006 —  if(document.form2.mac.value.search(/d{2}:d{2}:d{2}:d{2}:d{2}:d{2}/)==-1)[/CODE][/QUOTE]How does that allow for the entry of an alphabetic characters in the fourth and final sequence?
Copy linkTweet thisAlerts:
@HumperauthorAug 21.2006 — how do I change it to get it to work?? I dont know..


if I use all 00:00:00:00:00:00 it works fine.. how do I make it so that it will accept letters and numbers
Copy linkTweet thisAlerts:
@LogicianAug 21.2006 — how do I change it to get it to work?? I dont know..


if I use all 00:00:00:00:00:00 it works fine.. how do I make it so that it will accept letters and numbers[/QUOTE]
As I understand it, in a MAC address all the characters are HEX: 0-9A-F. Is that what you intend to allow?
Copy linkTweet thisAlerts:
@HumperauthorAug 21.2006 — yes they should be able to enter letters or number... but it has to be in the following format 00:10:2d:4f:63:2a

letter can be cap or lower case.. doesnt matter
Copy linkTweet thisAlerts:
@HumperauthorAug 21.2006 — I got it working.. had to replace the 'd' with a 'w' so that I could use letters and number.
Copy linkTweet thisAlerts:
@felgallAug 21.2006 — instead of d{2} you need [dABCDEF]{2} to allow for the hexadecimal digits

w will allow other invalid characters to be entered.
×

Success!

Help @Humper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...