working on it ...

Filters

Explore Public Snippets

Sort by

Found 5 snippets matching: "numeric validation"

    public by p.kontalis  2765  1  5  0

    Numeric Validation on TextFields

    Imports System.Globalization
    Public Class Form 1
    
      Private Sub SheetFromWeight_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim YourPreferableCulture as String = "en-US"
        CultureInfo.DefaultThreadCurrentCulture = New CultureInfo(YourPreferableCulture)
        CultureInfo.DefaultThreadCurrentUICulture = New CultureInfo(YourPreferableCulture)
      End Sub
      
      Private Sub Numbers_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged,
                                                                                   TextBox2.TextChanged,
                                                                                   TextBox3.TextChanged
         If Not IsNumeric(sender.Text) Then sender.text = ""
         If sender.Text.contains(",") Then
              sender.text = sender.text.replace(",", ".")
              sender.select(sender.text.length, 0)
         End If
      End Sub                                  
    End Class

    external by Jay W Johnson  22  0  1  0

    KnockoutJS numeric validation function modified to allow a single period.

    KnockoutJS numeric validation function modified to allow a single period.: ko_extend_numeric.js
    // Modified version of code at http://knockoutjs.com/documentation/extenders.html
    
    ko.extenders.numeric = function(target, precision) {
        //create a writable computed observable to intercept writes to our observable
        var result = ko.pureComputed({
            read: target,  //always return the original observables value
            write: function(newValue) {
                console.log(typeof newValue, newValue);
                var current = target(),
                    roundingMultiplier = Math.pow(10, precision),
                    newValueAsNum = isNaN(newValue) ? 0 : parseFloat(+newValue),
                    valueToWrite = Math.round(newValueAsNum * roundingMultiplier) / roundingMultiplier;
     
                //only write if it changed and allow a single period at end
                if (String(newValue).indexOf('.') === String(newValue).length-1) {
                    target(newValue);
                } else if (valueToWrite !== current) {
                    target(valueToWrite);
                } else {
                    //if the rounded value is the same, but a different value was written, force a notification for the current field
                    if (newValue !== current) {
                        target.notifySubscribers(valueToWrite);
                    }
                }
            }
        }).extend({ notify: 'always' });
     
        //initialize with current value to make sure it is rounded appropriately
        result(target());
     
        //return the new computed observable
        return result;
    };
    
    

    external by ismo1106  117  0  2  0

    Input Numeric Validation

    Input Numeric Validation: numericInput.js
    (function(b){var c={allowFloat:false,allowNegative:false};b.fn.numericInput=function(e){var f=b.extend({},c,e);var d=f.allowFloat;var g=f.allowNegative;this.keypress(function(j){var i=j.which;var h=b(this).val();if(i>0&&(i<48||i>57)){if(d==true&&i==46){if(g==true&&a(this)==0&&h.charAt(0)=="-"){return false}if(h.match(/[.]/)){return false}}else{if(g==true&&i==45){if(h.charAt(0)=="-"){return false}if(a(this)!=0){return false}}else{if(i==8){return true}else{return false}}}}else{if(i>0&&(i>=48&&i<=57)){if(g==true&&h.charAt(0)=="-"&&a(this)==0){return false}}}});return this};function a(d){if(d.selectionStart){return d.selectionStart}else{if(document.selection){d.focus();var f=document.selection.createRange();if(f==null){return 0}var e=d.createTextRange(),g=e.duplicate();e.moveToBookmark(f.getBookmark());g.setEndPoint("EndToStart",e);return g.text.length}}return 0}}(jQuery));
    
    

    external by kritik  82  0  1  0

    Fast fix her with numerical validation

    Fast fix her with numerical validation: numerical_validation.rb
    module ActiveModel
    
      module Validations
        class NumericalityValidator < EachValidator # :nodoc:
          private
          def record_attribute_changed_in_place?(record, attr_name)
            false
          end
        end
      end
    end
    
    
    

    external by Albioncode  7  0  1  0

    Regex vs char-by-char numeric validation

    Regex vs char-by-char numeric validation: Program.cs
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading.Tasks;
    
    namespace Integer_Comparison
    {
        class Program
        {
            const int NUM_TESTS = 5000000;
            static void Main(string[] args)
            {
                Console.WriteLine("Running {0} tests on each method", NUM_TESTS);
                Console.WriteLine();
                Console.WriteLine("Beginning Regex test");
                Stopwatch stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < NUM_TESTS; i++)
                {
                    Regex.IsMatch("" + i, "^[0-9]+$");
                }
                stopwatch.Stop();
                Console.WriteLine("Finished regex test, took {0}ms", stopwatch.ElapsedMilliseconds);
    
                Console.WriteLine("Beginning char-by-char test");
                stopwatch = Stopwatch.StartNew();
                for (int i = 0; i < NUM_TESTS; i++)
                {
                    IsInteger("" + i);
                }
                stopwatch.Stop();
                Console.WriteLine("Finished char-by-char test, took {0}ms", stopwatch.ElapsedMilliseconds);
    
    
                Console.ReadKey(true);
            }
    
            private static bool IsInteger(string input)
            {
                if (input == null)
                {
                    return false;
                }
                int length = input.Length;
                if (length == 0)
                {
                    return false;
                }
                int i = 0;
                if (input[0] == '-')
                {
                    if (length == 1)
                    {
                        return false;
                    }
                    i = 1;
                }
                for (; i < length; i++)
                {
                    char c = input[i];
                    if (c <= '/' || c >= ':')
                    {
                        return false;
                    }
                }
                return true;
            }
        }
    }
    
    

    List Complete ( 5 snippets total )

    • Public Snippets
    • Channels Snippets