By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,567 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,567 IT Pros & Developers. It's quick & easy.

Better way to check for characters

P: n/a
This function checks if a string contains commas or dots. Is there a
simpler, better way to write the function?

function CheckCharacters(x) {
var CharPos = x.indexOf(",")
if (CharPos != -1) {
alert("String contains commas.");
}
CharPos = x.indexOf(".")
if (CharPos != -1) {
alert("string contains dots.");
}
}
I call it using:

<form name="myForm" ... >
....
<input type="text" name="txtBox"
onBlur="CheckCharacters(myForm.txtBox.value)">
....
</form>
Thanks.

Oct 18 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Andyza wrote on 18 okt 2007 in comp.lang.javascript:
This function checks if a string contains commas or dots. Is there a
simpler, better way to write the function?

function CheckCharacters(x) {
var CharPos = x.indexOf(",")
if (CharPos != -1) {
alert("String contains commas.");
}
CharPos = x.indexOf(".")
if (CharPos != -1) {
alert("string contains dots.");
}
}
Are you trying to let us do your school assignment?

Didn't you read recent postings about RegEx?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 18 '07 #2

P: n/a
On Oct 18, 9:00 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
Are you trying to let us do your school assignment?
LOL!
Didn't you read recent postings about RegEx?
Which one are you referring to?

Oct 18 '07 #3

P: n/a
Andyza wrote on 18 okt 2007 in comp.lang.javascript:
On Oct 18, 9:00 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>Are you trying to let us do your school assignment?

LOL!
It is not a laughing matter,
as your(!!) schooling will suffer.
>Didn't you read recent postings about RegEx?

Which one are you referring to?
'read recent' says it all: all.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 18 '07 #4

P: n/a
On Oct 18, 10:18 am, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:
>
It is not a laughing matter,
as your(!!) schooling will suffer.
I "dropped out" of school many years ago... But thank you for your
concern Evertjan.

:->

Oct 18 '07 #5

P: n/a
Andyza wrote on 18 okt 2007 in comp.lang.javascript:
On Oct 18, 10:18 am, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:
>>
It is not a laughing matter,
as your(!!) schooling will suffer.

I "dropped out" of school many years ago... But thank you for your
concern Evertjan.
you are welcome.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 18 '07 #6

P: n/a
On Oct 18, 10:18 am, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:
>
It is not a laughing matter,
as your(!!) schooling will suffer.
I "dropped out" of school many years ago... But thank you for your
concern Evertjan.

:->

Oct 18 '07 #7

P: n/a
On Oct 18, 11:39 am, Andyza <and...@webmail.co.zawrote:
On Oct 18, 10:18 am, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:
It is not a laughing matter,
as your(!!) schooling will suffer.

I "dropped out" of school many years ago... But thank you for your
concern Evertjan.

:->
Mmm. Looks like my schooling DID suffer! Sorry for the double-post...

Oct 18 '07 #8

P: n/a
In comp.lang.javascript message <11*********************@q3g2000prf.goog
legroups.com>, Wed, 17 Oct 2007 23:49:19, Andyza <an****@webmail.co.za>
posted:
>This function checks if a string contains commas or dots. Is there a
simpler, better way to write the function?
Yes. <URL:http://www.merlyn.demon.co.uk/js-valid.htm>.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Oct 18 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.