Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by giano574 · Jun 02, 2015 at 12:06 PM · inputfieldlanguagedecimalcomma

Change InputField decimal mark

The default decimal mark of a "Decimal Number" InputField is '.' How do you change it to ',' (comma) depending on the language?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nwhis · Jun 02, 2015 at 12:38 PM 0
Share

I don't think you can...

avatar image giano574 · Jun 02, 2015 at 12:48 PM 0
Share

Sorry, I should have been more clear. I am talking about mobile devices where pressing the "comma" button on the keyboard does nothing, because the InputField only accepts numbers and a decimal mark which is '.'

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Fornoreason1000 · Jun 02, 2015 at 12:44 PM

Actually its pretty simple, or complicated, depending on how "accurate" you want to be. What you want would be Regular Expressions. the reason I say regular repressions is instead of just String.Replace is so you don't just replace every "." such as full stops to ",".

Basically with decimals you have a a number after and before the decimal like this

0.2938498 or 111.348569

its up to you if you want to allow these

.03 0.999125

We wanbt to filer anything that isn't either a number or a "," / "." so either way your regular expression will look like this.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Text.RegularExpressions;
 
 public class EURODecimalInput : MonoBehaviour {
 
     //Set thius to true if you want to use commas instead of fullstops
    public bool useComma = false;
  
 
 
   /// <summary>
   /// This will get called by the OnTextChanged Event
   /// Make sure you use the Dynamic Text version not the verison that will let you edit the string
   /// </summary>
   /// <param name="input"></param>
   public  void ValidateStringCharacters(string input)
     {
         //get out input feild, even though we just fired an event from it
         InputField InputField = GetComponent<InputField>();
 
         //assign our regular expression string, it will be different if you use commas hence the "if"
         string regexp = @"[^0-9\.]?";
         if (useComma)
         {
             //commas don't neeed escaping
             regexp = @"[^0-9,]?";
         }
 
       //Assign out regex Object
          Regex regex = new Regex(regexp);
 
         //Replace anything that isn't a number with empty
         input =  regex.Replace(input, "");
 
 
          //print(input);
          //Apply our Validated string
          InputField.text = input;
 
     }
 }
 

OnValitadateString() is fired from the On Value Change event on your Input field. You will also need to change your Input type to "Standard" or it will not work correctly.

Sorry for the confusion Earlier,

Hope it helps

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image giano574 · Jun 02, 2015 at 12:57 PM 0
Share

Sorry, I should have been more clear. I am talking about mobile devices where pressing the "comma" button on the keyboard does nothing, because the InputField only accepts integers and a decimal mark which is '.' I want to be able to change this depending on the selected (or device) language.

avatar image Fornoreason1000 · Jun 02, 2015 at 01:16 PM 0
Share

ok... more or less the same , but you have to somehow hook the input string. or you could do the character validation manually. I'm not sure what Unity does but you can use Regular expressions for that. Hold on I'll change my Answer.

avatar image Fornoreason1000 · Jun 02, 2015 at 02:25 PM 0
Share

Answer Updated, it should do the trick

avatar image giano574 · Jun 02, 2015 at 03:20 PM 0
Share

I did something similar to your solution using InputField.onValidateInput, but the problem is that Unity does not allow for a comma to be entered, when the keyboardType is NumbersAndPunctuation or NumberPad. Even when setting the characterValidation to none the default input validation still invokes and removes anything other than digits or punctuations. This applies to mobile platforms only.

It seems right now the only solution is to make a custom InputField.

avatar image Fornoreason1000 · Jun 03, 2015 at 09:03 AM 0
Share

I left the content type to Standard If your worried about the mobile keyboard thing, you might just make an inbuilt one in your game

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

IME(Input Method Editor) Chinese Pin yin 0 Answers

Unity changing decimal points to decimal commas? 1 Answer

Mobile device change input field (comma/point) 0 Answers

Only allow english mobile keyboard in inputfield UGUI 0 Answers

How to add more commands in the ToString(); 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges