Você está na página 1de 1

1/28/2016

How to use regexp to insert decimal numbers in a field element! | Fabrik

Login

Home

Forums

SearchForums

Wiki

Members

RecentPosts

Home Forums Fabrik2.x FrequentlyAnsweredQuestions

Howtouseregexptoinsertdecimalnumbersinafield
element!
Francesco
New Member

Let'sthinkafieldelementinaform,whereusercanputinonlydecimalnumbers,inthisformat:
1)thefirstnumberhastobe1or0
2)thesecondcharactermustbe'.'or','anditisalwaysrenderedas','
3)thedecimalpartmustcontain3numbers,eventuallyfilledinwith0(zero)
4)'0'and'0,'arerenderedas''(emptystring)
Forexample:
1,1231,0000.999arerightnumbers
a,9992,3210arewrongnumbersandsoarenotaccepted!
Youcandoitputtingthisjavascriptcode
inthekeyupevent:
if(this.value.length==1){this.value=this.value.replace(/[^01]/,'')}
if(this.value.length==2){this.value=this.value.replace(/[.]$/,',')this.value=this.value.replace(/[^,]$/,'')}
if(this.value.length>2){this.value=this.value.replace(/[^09]$/,'')}
intheblurevent:
if(this.value.length>1){temp=this.value+'000'this.value=temp.substr(0,5)}
if(this.value=='1'||this.value=='1,'){this.value='1,000'}
if(this.value=='0'||this.value=='0,000'){this.value=''}

ForRoband/orHugh:thisthreadshouldbemovedintheFAQssection!
http://fabrikar.com/forums/index.php?threads/how-to-use-regexp-to-insert-decimal-numbers-in-a-field-element.8905/

1/3

Você também pode gostar