/    Sign up×
Community /Pin to ProfileBookmark

Javascript regular expression

Hi i am using this form to validate my input

[CODE]function validateForm() {
var name = document.getElementById(“name”);
var descp = document.getElementById(“descp”);
var language = document.getElementById(“language”);
var txtFileName = document.getElementById(“txtFileName”);
var alphaNumExp = /^[a-zA-Z0-9 _-]+$/;
var isValid = true;
if ((name.value === “” || name.value.length < 1 || name.value.length > 30) && !name.value.match(alphaNumExp)) {
isValid = false;
}
if ((descp.value === “” || descp.value.length < 1 || descp.value.length > 1000) && !descp.value.match(alphaNumExp)) {
isValid = false;
}
if (language.value === “”) {
isValid = false;
}
if (txtFileName.value === “”) {
isValid = false;
}

document.getElementById(“btnSubmit”).disabled = !isValid;

}[/CODE]

for a form. It checks everything else correctly EXCEPT for the alpha numeric part. Any ideas?? I am new to JS writing on my own(just was using other’s scripts)

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@adarshakbauthorJan 21.2011 — oh! ya such a small error just && should be || ?

Now another error.. may be silly like this !!! but still learning... my form is not submitting know why?

Here is the changed code
[CODE]function validateCardDetails()
{
var name = document.getElementById("name");
var descp = document.getElementById("descp");
var language = document.getElementById("language");
var txtFileName = document.getElementById("card");
var alphaNumExp = /^[a-zA-Z0-9 _-]+$/;
var isValid = true;
if ((name.value === "" || name.value.length < 1 || name.value.length > 30) || !name.value.match(alphaNumExp)) {
isValid = false;
}
if ((descp.value === "" || descp.value.length < 1 || descp.value.length > 1000) || !descp.value.match(alphaNumExp)) {
isValid = false;
}
if (language.value === "") {
isValid = false;
}
if (txtFileName.value === "") {
isValid = false;
}

return isValid;

}

function handleSubmit()
{
var validate = validateCardDetails();
if(validate === true)
{
alert("reached here");
document.greetingCardAdder.submit();
}
}[/CODE]


I get to the alert box but the submit is not working here is the form's part
form action="other_php_files/Uploader.php" method="post" enctype="multipart/form-data" name="greetingCardAdder" class="jNice">[/QUOTE]
×

Success!

Help @adarshakb 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...