Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with RegExp...

Status
Not open for further replies.

Markh51

Programmer
May 20, 2003
81
0
0
GB
Ok, up to now everthing works with my RegExp:

^[a-zA-Z]+[- a-zA-Z]?[a-zA-Z]+$

I can enter:

the cat
the-cat

but not:
the cat sat
the-cat-sat

I need to modify the above RegExp so you can have Spaces or "-" WITHIN a sentence BUT not in pairs or more, only by themselves

i.e.

the-cat-sat
the cat sat

NOT:

the--cat-sat
the cat sat

Thanks in advance.
 
Lrnmore,

If I use your RegExp:

/[^a-zA-Z\s-]|(\s\s)|(--)|(\|(-\s))/g

it works fine, but when I try to use your expression in ColdFusion it works fine as well but if I enter:

word$&*word word, it lets me enter that too, why wont the RegExp work in CF the same as it does in JS ?

Thanks.
 
It will not allow me to put word--word.

Here is the entire page. Try it out -

<HTML>
<HEAD>
<TITLE>Reg Exp</TITLE>


<script type=&quot;text/javascript&quot;>

/*
No double spaces or double - (&quot; &quot; or &quot;--&quot;)
*/

var reg = /[^a-zA-Z\s-]|(\s\s)|(--)/g;
function A(a){
var str = a;
if(str.match(reg)){
alert(&quot;bad char&quot;);
}

}
</script>



</HEAD>

<body>
<form><input type = &quot;text&quot; onblur = &quot;return A(this.value);&quot;></form>
</html>
 
Lrnmore,

If I use your RegExp:

/[^a-zA-Z\s-]|(\s\s)|(--)|(\|(-\s))/g

it works fine, but when I try to use your expression in ColdFusion it works fine as well but if I enter:

word$&*word word, it lets me enter that too, why wont the RegExp work in CF the same as it does in JS ?

Thanks
 
Mark,

I see your ? about CF, don't know, but the string is still
not getting to you correctly...
Try this reg exp in cold fusion.

Code:
var tststr = /[^a-zA-Z\s-]|(\s\s)|(--)|(\s-)|(-\s)/g;
[code]
One Last Time


2b||!2b
 
It works fine like I said, but it allows me to enter:

word$£^$%^&^word

why does it let me enter any old crap in between the words ?

This only does this in CF, not when it is running as a HTM page with JS !

Mark
 
Did you use this last string:

var tststr = /[^a-zA-Z\s-]|(\s\s)|(--)|(\s-)|(-\s)/g;

There is an open &quot;(&quot; in the one you indicated you were
using. The &quot;(\|(-\s))&quot; in the first string could be the problem.

2b||!2b
 
yes I used the last string.

As I said works fine in a JS app but not CF ?

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top