473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Better way to check for characters

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
8 1123
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Robert | last post by:
Hi, I was wanting to write some code to work out whether I needed st, nd rd or th in my dates. While the code below works, I am certain that there is a better way.... if (($daterep == "1") ||...
27
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
5
by: Hugo Elias | last post by:
Hi all, I have an idea for a better IDE. Though I don't have the skills required to write such a thing, if anyone's looking for a killer app, maybe this is it. If I'm typing at a rate of 10...
9
by: Randell D. | last post by:
Folks, I have a large amount of values to store (we're talking tens, if not hundreds of bytes). I need this for a client side application - ignore the security consequences for the moment -...
14
by: deko | last post by:
Is there a way to check user input for illegal characters? For example, a user enters something into a text box and clicks OK. At that point I'd like to run code such as this: illegal =...
4
by: Himanshu Singh Chauhan | last post by:
Hello all! I am a newbie in C world. I was making a program from K&R (1-17). I made 2 functions and found that same problem could be solved with 1. Making new varibles (array, 2 or more). 2....
3
by: Al | last post by:
Hello, Sorry for the silly question: How do I insert Check Mark into RichTextBox? I can’t find the ascii code for it. Thanks Alex
204
by: Masood | last post by:
I know that this topic may inflame the "C language Taleban", but is there any prospect of some of the neat features of C++ getting incorporated in C? No I am not talking out the OO stuff. I am...
5
by: ashurack | last post by:
I found a stored procedure online a while back and want to inplement it. The only problem is that it doesn't check to see if the number generated is currently in use in the DB. I know it's really...
28
by: Joey Martin | last post by:
One of my servers got hacked with the SQL injection due to poor coding. So, I had someone write a stored procedure and new code. But, to me, it looks just as flawed, even using the stored...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.