textField.restrict - how just allow one decimal place

Hello

I read somewhere on the textField.restrict.

I use it to limit user input to just the numbers and the decimal point.

a.textField.restrict = '. '. 0-9 ";

However, I find that the user can input more than one decimal place.

Does anyone know how to limit user input to just one decimal place?

Thanks for the help.

This should work for you

package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.events.TextEvent;

public class Test extends Sprite
    {
    public function Test()
        {
        var tf:TextField = new TextField();
        tf.type = TextFieldType.INPUT;
        tf.border = true;
        tf.width = 200;
        tf.height = 16;
        tf.x = tf.y = 20;
        tf.restrict = ".0-9"
        tf.addEventListener(TextEvent.TEXT_INPUT, restrictOneDecimal);

        addChild(tf);
        }

    function restrictOneDecimal(evt:TextEvent):void
        {
        var matches:Array = evt.currentTarget.text.match(/\./g);

        if  (evt.text == "." && matches.length >= 1)
            evt.preventDefault();
        }
    }
}

or if you want to restrict to one decimal place, but also a number of digits after the decimal point:

function restrictDecimalPlaces(evt:TextEvent):void
    {
    var matches:Array = evt.currentTarget.text.match(/\./g);
    var allowedDecimalPlaces:uint = 2;

    if  ((evt.text == "." && matches.length >= 1) ||
        (matches.length == 1 && (evt.currentTarget.text.lastIndexOf(".") + allowedDecimalPlaces < evt.currentTarget.text.length)))
        evt.preventDefault();
    }

Tags: BlackBerry Developers

Similar Questions

  • Showing results with one decimal two. Force the decimal.

    Hello

    Im a simple computing of writing device.

    You enter a digit, press one of the two buttons to multiply by a number, and then the result is displayed. The result is copied hide the result from the button you press on and visa versa.

    I'm having a problem to display the result with a decimal point two constant.

    I'm using strings and so do not know how to do this.

    Here is my code:

    import flash.events.MouseEvent;

    restrict entry to only numbers textfield

    txtInput.Restrict = "0-9";

    restrict the input textfield only a two-digit

    txtinput.maxChars = 6;

    event listeners

    btnW.addEventListener (MouseEvent.CLICK, WHandler);

    btnC.addEventListener (MouseEvent.CLICK, CHandler);

    btnW.addEventListener (MouseEvent.CLICK, hideC);

    btnC.addEventListener (MouseEvent.CLICK, hideW);

    functions

    function WHandler (e:MouseEvent): void

    {

    calculation of white

    var answerW:Number = Number (txtinput.text) * Number (0.90);

    txtWResult.text = answerW.toString ();

    }

    function of CHandler (e:MouseEvent): void

    {

    calculation of the color

    var answerC:Number = Number (txtinput.text) * Number (0.99).

    txtCResult.text = answerC.toString ();

    }

    function hideC (e:MouseEvent): void

    {

    Hide the result color

    txtCResult.visible = false;

    txtWResult.visible = true;

    }

    function hideW (e:MouseEvent): void

    {

    Hide the white result

    txtWResult.visible = false;

    txtCResult.visible = true;

    }

    After having had a look online I found these two resources:

    http://helpx.Adobe.com/Flash/KB/rounding-specific-decimal-places-Flash.html

    and

    http://StackOverflow.com/questions/11469321/decimals-to-one-decimal-place-in-AS3

    But I'm confused when combining these techniques with ropes.

    Any help would be greatly appreciated,

    Thanks in advance

    Mr B

    Use the toFixed() class number instead of the toString() method.  The result is a string that contains the number of decimal places you specify.

    var answerW:Number = Number (txtinput.text) * Number (0.90);

    txtWResult.text = answerW.toFixed (2);

    var answerC:Number = Number (txtinput.text) * Number (0.99).

    txtCResult.text = answerC.toFixed (2);

  • Hello, I would like to know how to transfer one of my two 'belonging' to another computer because I just bought a new Mac...? Or how to cancel it on my old laptop so I can activate it on my new computer. Thank you very much!

    Hello, I would like to know how to transfer one of my two 'belonging' to another computer because I just bought a new Mac...? Or how to cancel it on my old laptop so I can activate it on my new computer. Thank you very much!

    Hi Virginia,

    You need to go under the Help menu of Muse option to disconnect and then install it on the other computer you want using the creative cloud desktop application.

    - Abhishek Maurya

  • How to truncate my query results in a column to reflect only 2 decimal places

    SELECT (COLUMNNAME/60) / 60 AS ACTHOURS
    FROM TABLENAME

    This request is currently converting seconds to hours, but some values are endless beyond the comma. I want only the results to show 2 decimal places.

    Can anyone suggest how to proceed?
    SELECT round((COLUMNNAME/60)/60,2) AS ACTHOURS_ROUND,
           trunc((COLUMNNAME/60)/60,2) AS ACTHOURS_CUT
    FROM TABLENAME;
    

    You can find the documentation here:

    http://docs.Oracle.com/CD/E11882_01/server.112/e10592/functions155.htm#i78633

    http://docs.Oracle.com/CD/E11882_01/server.112/e10592/functions221.htm#i79729

    Published by: hm on 26.04.2012 05:20

  • How to tour calculations with two decimal places (scaling of the form)

    Hello

    I created an order form where customers enter the amount of product that they want to order and the form shows the total amount payable (including transport and sales tax). According to the user input, the amount total resulting sometimes contains more than two decimal places. How do I turn calculations to two decimal places? Is it possible to do this form on the scale?

    I'm new to using Acrobat for calculations. Any help would be greatly appreciated! Thank you...

    This should be:

    Event.Value = util.printf ("%.2f", event.value);

  • How can I configure my calculator to round the number to 2 decimal places

    Can someone please help me get my calculator to view my answer to 2 decimal places

    Hello

    The calculator (calc.exe) does not have this feature.

    You can use any third party software that can support the feature.

    WARNING: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    I hope that helps!

  • How to make the calculation script to show 2 decimal places and stop rounding down to integers?

    Hello. First of all, thank you to those of you who have helped me create an interactive PDF file last year that worked perfectly if only integers are entered. This year, my client wants to show two decimal places in the calculations, and I'm back in this forum hoping to find the same expertise to make it happen.

    My form includes 43 fields for various monthly expenses. The sign of dollar for each field is part of the content of the form, not part of the scope of formatting. Users enter values directly in these fields, and the fields are formatted to display two decimal places. Each of these includes a the following validation script:

    Event.RC =! (event.value & & + event.value < 0);


    To the right of each of these fees, the fields are yes/no boxes ( expense Typecalled) that answer the question, "is this essential expense? The value of exports for Yes's 'essential', and the value of exports is "discretionary".


    A value entered in all areas of expenditure is directed to the field Total expenses by checking Yes or field Total discretionary spending by clicking No. two of these total fields are formatted to display two decimal places. In addition to long calculation scripts, the two totals fields include this custom validation script:

    If (event.value == "0") {event.value = util.printx ("", event.value)}

    Here's the problem: when values with two decimal places are entered in any area of expenditure, the calculation in two fields of total script rounded to the whole number closest. When 10.99 is entered in a field of expenditure and the Yes checkbox is checked, the value 10.00 is displayed in the field Total expenses . I want to display 10.99.

    For testing purposes, I inserted a new text field and did a simple calculation in choosing the fields of the somme and the values displayed correctly. The problem is definitely with the script in the two fields in total .


    I can drop the scripts of math here, but they are long and I'm not sure what the Protocol is super-long positions. I could also download the file, but I never did it and will need to understand this.

    Thank you for taking the time to read this. If you can help me, very well!

    To explicitly convert the field values for numbers, do something like this instead:

    var expense0 = + getField('monthly$.0').value,

    depenses1 = + getField('monthly$.1').value,

    etc.

  • How to convert the numeric value to 2 decimal places in java

    Hi all
    My requirement is a double value in the print format #, #. ##. I used the following code

    Double val = 1000;
    DecimalFormat d = new DecimalFormat("#,###.##");
    d.format (Val);

    the output I got is 1,000, but I need the output as 1 000,00


    Can someone please help?


    Thank you
    Sunny

    Felipe says:
    If you still need print 2 decimal places, use model #, #. # 00

    Nope.

    DB

  • To the number of decimal places control user input

    Hey everybody,

    I am all new to LabVIEW and just learn how it works. I was wondering if there was a way to allow user input to change the number of decimal places (the output of my function is infinitely extensible).

    I tried, but it did not work:

    Using a digital input, I appended a string with "%" + '[INPUT]' + 'f' with the number of function concat strings and string functions. I used the resulting string as the formatting string in the value format function.

    This doesn't quite work. The output should be something like "28.274", but instead, it displays "283f. Anyone know why? Is there a better way to do it?

    In addition, attach a picture of the front panel and diagram of block for clarity.

    (Yes, it's homework, but the assignment does not include allowing the user to adjust the number of decimal places, it's just something I would like to add.)

    Get rid of the number 2 for the width of your decimal string number.  It requires a space before a number to a number.  %. 6F is not equal to % .6f.  The string format don't quite understand the first format string.

    (PS.  It helps if you attach your VI.  In this way we can play with what you have rather than trying to recreate it from scratch.)

  • Number of decimal places in the recorded data

    Hello world

    I use the writing on measurement file Express VI and everything works well except for one thing. I have too many decimal places in my saved data. I really need 2 decimal places for my application. Is there a way I can fix this without having to open the file with Excel and format numbers?

    Just FYI I'm writing dynamic data, the VI write is configured for text (.lvm) file format, and it is delimited by tabs.

    Joint are two images: one of the worksheet of stored data, and the other is my writing to measure Express VI.

    Thank you!

    Laura

    Not with the express vi

    You CAN specify a format "%.2f" write to the spreadsheet file

  • How to allow only .gov Web sites on Windows XP using the installation of the broad-band

    How to allow websites .gov only on Windows XP. Use BSNL broadband. Made of internet sharing in LAN.

    Concerning

    Maton

    Hi Matt,

    This forum is for MSE who cannot restrict access of Web site you want.

    One of the possible methods that comes to mind uses the Parental http://www.windows-help-central.com/parental-controls-in-windows-xp.html may control with Windows Live Family Safety http://explore.live.com/windows-live-family-safety?os=other (according to the version of XP and whether or not you have a workgroup or domain LAN).  When you set up, allow *.gov, but reject all other types you can imagine (I don't think there is a way to allow only .gov, but you can exclude most if not all of the other busiest - check domain name registrars to get a list of options).  If you use a domain, way to go would be with a custom domain group policy to restrict access on all of the network (except perhaps the server or individuals of special category in Active Directory if you want).

    If that is not the case, and I think it might, please repost your question in the following forum to get the expert assistance you need: http://answers.microsoft.com/en-us/windows/forum/windows_xp-networking?page=1&tab=all.

    I hope this helps.

    Good luck!

  • Tour of metric to two decimal places by using [math]: tour

    I use the following psobject to extract performance data, but I have around two of the measures with two decimal places. Usually, I would use [math]: round ($var, 2) but I do not know how to integrate this into the code and settings, I need are AvgMem and AvgCPU.

    $groups | % {

    New-object PSObject-property @ {}

    'TimeIndex' = $_. Group [0]. TimeStamp

    "AvgMem" = $_. Group | where {$_.} MetricId - eq "mem.usage.average"} | Measure-object-property value - average | Select - ExpandProperty average

    "AvgCPU" = $_. Group | where {$_.} MetricId - eq "cpu.usage.average"} | Measure-object-property value - average | Select - ExpandProperty average

    'TotalMemory' = $TotalMemory.Split(".") | Select - index 0

    'TotalCPU' = ((Get-cluster_$cluster_|_get-vmhost_|_%_{$_}_|_measure-object-property_cputotalmhz-sum).sum)

    "Cluster" = $cluster

    'Data center' = $DC

    "vCenter' = $vcenter
    "Home" = $VMSummary.Hostname

    }

    }

    Any help is appreciated

    Thanks in advance

    Do you have one loan try like this

    $groups | % {

    New-object PSObject-property @ {}

    'TimeIndex' = $_. Group [0]. TimeStamp

    "AvgMem" = [math]: Round (($_.)) Group | where {$_.} MetricId - eq "mem.usage.average"} | Measure-object-property value - average | Select average - ExpandProperty), 2)

    "AvgCPU" = [math]: Round (($_.)) Group | where {$_.} MetricId - eq "cpu.usage.average"} | Measure-object-property value - average | Select average - ExpandProperty), 2)

    'TotalMemory' = $TotalMemory.Split(".") | Select - index 0

    'TotalCPU' = ((Get-cluster_$cluster_|_get-vmhost_|_%_{$_}_|_measure-object-property_cputotalmhz-sum).sum)

    "Cluster" = $cluster

    'Data center' = $DC

    "vCenter' = $vcenter

    "Home" = $VMSummary.Hostname

    }

    }

  • Limitation of DISTANCE to two decimal places

    I pretty much get the Google Maps API, talking to my SQL database. For the results of my research, I have SQL code:

    SELECT *, (3959 * acos (cos (radians (".")))) $POST ["latitude"]. (radians (lat)))) * cos * cos ((LNG) radians: radians (".")) $POST ["longitude"]. ")) + sin (radians (". "))" $_POST ["latitude"]. ")) * sin (radians (lat))) AS distance FROM VenuesGeocodes1 HAVING distance < 100 ORDER BY LIMIT 0, 30;"

    That works very well, but will display the distance to 15 decimal places, which is an exaggeration full.

    How can I limit that to only two decimal places? I thought I just needed to change the distance to distance (10.2), but he doesn't like it.

    If anyone can let me know what need would be much appreciated.

    Thank you.

    If you use PHP, you can do it like this:

    $grandtotal = number_format($grandtotal,2,'.',',');

  • Digital formatting with Variable decimal places

    Acrobat 9 Pro, Windows XP

    I have created a form that has a number of text box form fields that must be numeric only by the applicant of the form. However, for any field data of this type, the number of digits that can be entered can vary from 0 to 3 and the applicant wants all decimal unnecessary to appear in the final output (for example, an entry "1.2" does not appear as "1,200"). The standard number formatting properties always show all decimals, so I know that it is not this way. No calculations will be made with one of these entries - the applicant form is simply enter data and then printing to make it readable for the end user.

    I know that the following line of JavaScript in the hit limit the digital input only Custom property, but how do I change the syntax to allow a decimal writing:

    Event.RC = (! event.change | / ^ \d$/.test(event.change))

    I probably also need a script to format for decimals, but I don't know where to look in the JavaScript for Acrobat QAnywhere or the JavaScript reference DND.

    Thanks in advance for any help.

    OK, here's a link to an example: https://workspaces.acrobat.com/?d=Xf5mboqmkpf-zRxB9MVAJw

    The code that is called in Format typing of the text events field and is in a JavaScript at the level of the document named "format". Post again if you have any questions.

  • Change the number of decimal places according to the value of the field

    Hello world

    I'm doing a form using Adobe Acrobat.

    I want a field that usually has only 2 decimal places, to have 4 decimal positions ONLY when necessary.

    Example: If the value of the field is 3.53 that's fine, but if the value is 3,5346 I want to show him this.

    I played around field properties and I realized that I need to use a custom format script. I don't know where to start, however. Can you point me in the right direction?

    Thank you in advance.

    I just threw together quickly and did not test, take is as a general guide. It is intended to be placed in a JavaScript to the document level and called from custom Format script of the field. You can not put it simply everything as the script to Format because of the way that Acrobat behaves when you do.

    The point of the script is to calculate the number to use as the first parameter to the AFNumberFormant function, which is that Acrobat uses when configuring a digital format. I couldn't think of a clever name for the function, so I leave it to you:

    function fmt1() {
    
        // Set the minimum number of digits to the right of the decimal
        var min = 2;
    
        // Get the field value, as a string
        var val = event.value;
    
        // Round to the nearest 10-thousand of a cent
        var rn = util.printf("%.4f", val);
    
        // Replace any trailing zeroes with nothing
        rn = rn.replace(/[0]+$/, "");
    
        // Get the number of characters after the decimal
        var num = rn.split(".")[1].length;
    
        // Set to the minimum if appropriate
        if (num < 2) num = 2;
    
        // Use built-in formatting function
        AFNumber_Format(num, 2, 0, 0, "\u20ac", true);
    
    }
    

    Call it like that in the case of the field Format:

    fmt1();
    

    If this isn't a calculated field, but the one who interacts with a user, you'll want to add a function with the swing, something like:

    function keystroke1() {
    
        AFNumber_Keystroke(2, 2, 0, 0, "\u20ac", true);
    
    }
    

Maybe you are looking for