/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Vaildation of Characters

Can Any One Tell Me A If Statement That Will Check For These Characters

[CODE]/:*?”<>|[/CODE]

Thank You

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@007JulienJul 10.2012 — An essay of search for one of these characters in strings...
[CODE]
[COLOR="Blue"]
// Multiple strings to split for tests[/COLOR]
var str="hello word !@<script>@How are you ?@Well 5/5 !@2*2 = 4@..."...@..|..@Good luck !".split('@');

[COLOR="Blue"]// The test for one of the following characters: /:*?"<>|
[/COLOR]for (var l=str.length,i=0;i<l;i++)
alert(str[i]+(/[\/:*?"<>]/.test(str[i])?' contains':' does not contain ')+' one of the indicated (/:*?"<>|) characters !');[/CODE]
All this characters (except colon, less and more) must be escaped with a backslash in the character class delimiter by the two square brakets...
Copy linkTweet thisAlerts:
@iGeekiHackiMattauthorJul 10.2012 — okay, is there a to put it in a if statement?(so after i validate if they typed something in or not i can check to see if they have a invalid characters entered.). Thank You For The Reply.
Copy linkTweet thisAlerts:
@jalarieJul 10.2012 — <i>
</i>InPut=prompt('What?','');
if (InPut.match(/^.*?[\/:*?"&lt;&gt;|].*?$/)) {
alert('Found one.');
} else {
alert('None found.');
}
Copy linkTweet thisAlerts:
@iGeekiHackiMattauthorJul 10.2012 — That Seems To Be Just What I Needed, Thank You So Much

and I Went To Your WebSite And Found Your Safe Sex Quote To be Very True ?
Copy linkTweet thisAlerts:
@jalarieJul 10.2012 — <i>
</i>InPut=prompt('What?','');
if (InPut.match(/^.*?[\/:*?"&lt;&gt;|].*?$/)) {
alert('Found one.');
} else {
alert('None found.');
}
[/QUOTE]


The caret (^) at the beginning forces the pattern to start at the beginning of the string.

The dollar sign ($) at the end forces the pattern to go all the way to the end of the string.

The dot-star-question-mark (.*?) sets allow us to ignore leading and trailing characters.

The square brackets ([]) surround multiple individual characters to seek.

Each of the individual characters is preceeded by a back-slash () so that it doesn't have any special meaning.
Copy linkTweet thisAlerts:
@iGeekiHackiMattauthorJul 11.2012 — That Helps Me A Lot Thank You Once Again.
×

Success!

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