Regular expression

T

Tony Johansson

Hello!

In lack of a better construction I use this small snipped where I replace
every character with a empty string ("") that is anything other then numeric
character 0-9 ot dot or comma.
As you can see in this statement after g, I have '' which replace invalid
character with empty string.
I hope there is a shorter construction where I can find invalid character to
be replaced with ''.
This construction says if enter character is within this
(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
replace this character with empty character ''.
So if I replace this (/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
with
(/ \D]
all work quite fine except that dot and comma is filtered out which I don't
want.


<input type="text" name="depthBow" id="txtDepthBow" size="20" onkeyup="if
(/[A-Za-z;:_!@£#¤%&/()=}{'´`€+*?\\[$-]/g.test(this.value)) this.value =
this.value.replace(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]/g,'')" />

//Tony
 
A

Arne Vajhøj

In lack of a better construction I use this small snipped where I
replace every character with a empty string ("") that is anything other
then numeric character 0-9 ot dot or comma.
As you can see in this statement after g, I have '' which replace
invalid character with empty string.
I hope there is a shorter construction where I can find invalid
character to be replaced with ''.
This construction says if enter character is within this
(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
replace this character with empty character ''.
So if I replace this (/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
with
(/ \D]
all work quite fine except that dot and comma is filtered out which I
don't want.

[^0-9.,]

or if the regex dialect treat period as special inside [] then:

[^0-9\.,]
<input type="text" name="depthBow" id="txtDepthBow" size="20"
onkeyup="if (/[A-Za-z;:_!@£#¤%&/()=}{'´`€+*?\\[$-]/g.test(this.value))
this.value =
this.value.replace(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]/g,'')" />

That looks like JavaScript.

So if you ask in a JavaScript group you may get much better responses.

Arne
 
T

Tony Johansson

Yes this work but now I can start with a comma or a dot.
How should I change it if there but start with a digit first ?
So start input with . or , should be filtered out

How you some good example for this Arne ?
Yes this is Javascript(JQuery) !

//Tony


Arne Vajhøj said:
In lack of a better construction I use this small snipped where I
replace every character with a empty string ("") that is anything other
then numeric character 0-9 ot dot or comma.
As you can see in this statement after g, I have '' which replace
invalid character with empty string.
I hope there is a shorter construction where I can find invalid
character to be replaced with ''.
This construction says if enter character is within this
(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
replace this character with empty character ''.
So if I replace this (/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
with
(/ \D]
all work quite fine except that dot and comma is filtered out which I
don't want.

[^0-9.,]

or if the regex dialect treat period as special inside [] then:

[^0-9\.,]
<input type="text" name="depthBow" id="txtDepthBow" size="20"
onkeyup="if (/[A-Za-z;:_!@£#¤%&/()=}{'´`€+*?\\[$-]/g.test(this.value))
this.value =
this.value.replace(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]/g,'')" />

That looks like JavaScript.

So if you ask in a JavaScript group you may get much better responses.

Arne
 
A

Arne Vajhøj

Arne Vajhøj said:
In lack of a better construction I use this small snipped where I
replace every character with a empty string ("") that is anything other
then numeric character 0-9 ot dot or comma.
As you can see in this statement after g, I have '' which replace
invalid character with empty string.
I hope there is a shorter construction where I can find invalid
character to be replaced with ''.
This construction says if enter character is within this
(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
replace this character with empty character ''.
So if I replace this (/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
with
(/ \D]
all work quite fine except that dot and comma is filtered out which I
don't want.

[^0-9.,]

or if the regex dialect treat period as special inside [] then:

[^0-9\.,]
Yes this work but now I can start with a comma or a dot.
How should I change it if there but start with a digit first ?
So start input with . or , should be filtered out

How you some good example for this Arne ?

You will need to change the logic a bit because it will no longer
be single character oriented.

Are you sure that you want replace and not just a validation?

Arne
 
B

bradbury9

El miércoles, 16 de enero de 2013 22:20:54 UTC+1, Tony Johansson escribió:
Yes this work but now I can start with a comma or a dot.

How should I change it if there but start with a digit first ?

So start input with . or , should be filtered out



How you some good example for this Arne ?

Yes this is Javascript(JQuery) !



//Tony





"Arne Vajhøj" skrev i meddelandet
On 1/16/2013 2:52 PM, Tony Johansson wrote:
In lack of a better construction I use this small snipped where I
replace every character with a empty string ("") that is anything other
then numeric character 0-9 ot dot or comma.
As you can see in this statement after g, I have '' which replace
invalid character with empty string.
I hope there is a shorter construction where I can find invalid
character to be replaced with ''.
This construction says if enter character is within this
(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
replace this character with empty character ''.
So if I replace this (/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]
with
(/ \D]
all work quite fine except that dot and comma is filtered out which I
don't want.

or if the regex dialect treat period as special inside [] then:
[^0-9\.,]
<input type="text" name="depthBow" id="txtDepthBow" size="20"
onkeyup="if (/[A-Za-z;:_!@£#¤%&/()=}{'´`€+*?\\[$-]/g.test(this.value))
this.value =
this.value.replace(/[A-Za-z;:_!@£#¤%&/()=}{'`´€+*?\\[$-]/g,'')" />
That looks like JavaScript.
So if you ask in a JavaScript group you may get much better responses.

If you are using JQuery, just use JQuery email validation, seems very easy:

$("#myform").validate({
rules: {
field: {
required: true,
email: true
}
}
});

http://docs.jquery.com/Plugins/Validation/Methods/email
 

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

Top