Number field validation to use dot and not comma

Forums General discussion Number field validation to use dot and not comma

Viewing 5 reply threads
  • Author
    Posts
    • #24048
      Maciek Grischke
      Participant

      Hi all,

      Is there a way to decline an entry in a number field with commas and to tell the user to use a full stop instead?

      SharePoint converts “14,5” to “145” and I need users to enter “14.5”.

      Many thanks.

    • #24050
      Maciek Grischke
      Participant

      I got it sorted via column validation using the following formula:

      =ISNUMBER(VALUE(TRIM(CLEAN([Column Name]))))

      but the column needs to be in a Text format, not a number format. I then use Flow to convert it back to a proper number.

      I wonder if there’s a way of using DFFS. No worries if not.

    • #24073
      Alexander Bautz
      Keymaster

      Hi,
      Add something like this to your Custom JS to replace “,” with “.”:

      jQuery("#dffs_YOUR_FIELDINTERNALNAME input").on("keyup",function(e){
          var str = jQuery(this).val();
          jQuery(this).val(str.replace(",","."));
      });

      Change “YOUR_FIELDINTERNALNAME” with your field internal name.

      Alexander

      • #28716
        Steve Jonasson
        Participant

        Thank you, Alex, it helped me a lot.
        In Czech, we have comma separator instead of a decimal dot.
        And I changed the event from “keyup” to “change” and it works perfectly.
        Steo

    • #25193
      Maciek Grischke
      Participant

      Thanks Alexander.

      Unfortunately, this is a text field and users can enter anything in there. Is there a way to replace any other character than a number with ‘no space’?

      I have a Flow built for this form and I’d like to avoid redoing the Flow, if possible.

    • #25197
      Maciek Grischke
      Participant

      Ok, I found a way to do this. Actually, a few ways, but which one is more appropriate or correct or are all of them correct?

      jQuery("#dffs_Title input").on("keyup",function(e){
          var str = jQuery(this).val();
          jQuery(this).val(str.replace(/[^0-9.]/g, ''));
      });
      

      or

      jQuery("#dffs_Title input").on("keyup",function(e){
          var str = jQuery(this).val();
          jQuery(this).val(str.replace(/[^\d.-]/g, ''));
      });
      

      both work and do what I need them to do, but what’s the difference?

    • #25215
      Alexander Bautz
      Keymaster

      The two are basically the same – the \d metacharacter is used to find a digit from 0-9.: https://www.w3schools.com/jsref/jsref_regexp_digit.asp

      This means you can use the one you find easiest to read / understand.

      Alexander

Viewing 5 reply threads
  • You must be logged in to reply to this topic.