Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

465
Views
How to convert string to lowercase? .toLowerCase() not working properly

I want to make an input field that returns imputed text in lower case. I'm using expo

const [login, setLogin] = useState('');
//...
<TextInput style={{backgroundColor:'#bbb'}}
   value={login}
   onChangeText={(val)=>setLogin(val.toLowerCase())}
   placeholder="email or username"
></TextInput>

I'm getting a strange result when testing it on my device.

my input: 'K' => login = 'k'

my input: 'k' => login = 'kkk'

my input: 'k' => login = 'kkkkkkk'

You may need to try a few times to recreate my result as it doesn't happen every time. When I remove .toLowerCase(), it works correctly.

I made runnable example for you to test. Running it in web mode works fine, but when I run it on my device, the same error is occurring as in my project.

Here is a video of what's happening to me when I run it on android 10. You can see that it doesn't happen always, but sometimes it registers as if I've pressed "q" three times when I've only pressed it twice

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I think you run into a known react-native bug, related to text inputs and capitalization on Android platform. Open github issue #27449.

As a workaround you can force the text input to use the visible-password keyboard type on Android.

Working example for you to test:

import React, { useState } from 'react';
import { Text, View, StyleSheet, TextInput } from 'react-native';
import { Platform } from 'react-native';

export default function App() {
  const [login, setLogin] = useState('');
  return (
    <View style={styles.container}>
      <TextInput style={{backgroundColor:'#bbb'}}
        value={login}
        onChangeText={(val)=>setLogin(val.toLowerCase())}
        keyboardType={Platform.OS === 'ios' ? 'default' : 'visible-password'}
        placeholder="email or username"
      ></TextInput>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    padding: 80,
  },
});

Credit for the workaround goes to simon-davies-avtura

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!