0

How to apply a mask to a textbox value while user is typing? JavaScript REGEX issue

asked 2009-11-17 13:51:32 +0800

gyowanny gravatar image gyowanny
283 1 2 6

updated 2009-11-18 06:11:43 +0800

Hi

I've been trying to apply a certain mask to a textbox value while the user is typing. Basically I'm using the onChanging event.
The point here is that I don't want to use java classes to format the value since it turns up into a server side operation, so I would like to do that in CSA (Client Side Actions) mode.
So when I type something in the textbox the javascript function called apply_mask is returning an empty string.
What is wrong with the code below? Just wondering if the javascript's regex is wrong:

.zul file

   <script src="/scrips/masking.js" language="JavaScript"/>
   <textbox id="maskedBox" onChanging="javascript:maskedBox.value=apply_mask(event.value)" />

masking.js file

function apply_mask(v){
    v=v.replace("/\D/g","");     
    v=v.replace("/^(\d{2})(\d)/","$1.$2") ;            
    v=v.replace("/^(\d{2})\.(\d{3})(\d)/","$1.$2.$3") ;
    v=v.replace("/\.(\d{3})(\d)/",".$1/$2") ;          
    v=v.replace("/(\d{4})(\d)/","$1-$2")  ;           
    return v;
}

Thanks

Gyo

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-11-18 08:06:09 +0800

gyowanny gravatar image gyowanny
283 1 2 6

Nobody here ever had to apply some javascript to format the text while user is typing?

link publish delete flag offensive edit

answered 2009-11-18 12:35:42 +0800

gyowanny gravatar image gyowanny
283 1 2 6

Hi Folks,

Does anybody here used a javascript to handle the data while user is typing???

link publish delete flag offensive edit

answered 2009-11-18 13:19:35 +0800

YamilBracho gravatar image YamilBracho
1722 2

Use jQuery numeric plugin (http://plugins.jquery.com/project/Numeric)

link publish delete flag offensive edit

answered 2009-11-18 18:47:00 +0800

samchuang gravatar image samchuang
4084 4

Hi ~~

Have you debug into javascript function, and see what really happen ?? you could find out which line cause return empty string

link publish delete flag offensive edit

answered 2009-11-18 19:02:31 +0800

samchuang gravatar image samchuang
4084 4

I have tried your sample code, and I don't get a empty string~

here is a javascript Regular Expression tutorial, hope could help you

link

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-17 13:51:32 +0800

Seen: 902 times

Last updated: Nov 18 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More