Better way to check for characters

A

Andyza

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.
 
E

Evertjan.

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?
 
E

Evertjan.

Andyza wrote on 18 okt 2007 in comp.lang.javascript:
I "dropped out" of school many years ago... But thank you for your
concern Evertjan.

you are welcome.
 
A

Andyza

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,150
Messages
2,570,853
Members
47,394
Latest member
Olekdev

Latest Threads

Top