/    Sign up×
Community /Pin to ProfileBookmark

Checking for a character

Similar to checking for valid email addresses I need to check for just a slash in a form field. I know nothing about regular expressions so my attempts at hacking a email validation script have not paid off. I just need to make sure users do not enter a slash in a description field.

If someone could please point me to a sample script that would be great!!! I look at regular expressions and about loose my mind.

THANKS!!!!!!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mishkinAug 29.2006 — ok, this is easy you'll be pleased to hear. I'll assume your field is a standard

<input type="text">. When you declare it give it a unique ID, for example:

<input type="text id="uniqueID">.

Next have your submit button call this function.

checkField()

{

fieldValue = document.getElementById("uniqueID")

if(fieldValue.value.indexOf("/"))

{

alert("sorry, '/' is an illegal character")

}

else

{

alert("There was no '/' found")

}

}

Or some variant of that should do the trick.
Copy linkTweet thisAlerts:
@IRHuskerauthorSep 05.2006 — Worked perfectly for me, thank you very much!
×

Success!

Help @IRHusker 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,
)...