Adding form validation in react-native, removing extra spaces

Asked by Salvador Hodge on
9 Answers

Answer by Kaiya Schmitt

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. ,when I add form validation it looks like this (2): ,Making statements based on opinion; back them up with references or personal experience.

Conditionally render the error like below

emailErrorField && <View style={styles.ErrorStyle}><Text style={{color: 'red', fontWeight: 'bold'}}>{emailError}</Text></View>

Answer by Millie Powell

Answer by Murphy Woods

Step 1: Create a React application using the following command:,Trim white space means removing white spaces from the text input from both start and end. The following example shows how to trim white space from text input in ReactJS.,The following will be the output if the user enters input with white space from both the end. You can see that the final output text is trimmed from both the side by removing white space.

Step 1: Create a React application using the following command:

npx create-react-app foldername

Step 2: After creating your project folder i.e. foldername, move to it using the following command:

cd foldername
npm install validator

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Answer by Zayd Hayes

Formatting the String Using replace(),Test the application by entering any string in the input field with spaces in between, and hit the Format String button. You will see the resultant string rendered with non-breaking spaces on the page. ,Essentially, the nowrap attribute collapses all sequences of whitespaces into a single one, and text keeps rendering on the same line unless a line break is encountered.

1npx create-react-app react-read-more

Answer by Kadence Raymond

On the Form tag and on the individual inputs I have placed noValidate (noValidate in jsx turns into novalidate in html). Adding this doesn't disable form validation. It only prevents the browser from interfering when an invalid form is submitted so that we can “interfere” ourselves.,We are going to build our form validation from this point and do all of the JavaScript logic ourselves. Currently the form does not submit or work in anyway, it has only been styled.,We are getting close to the home stretch, we have a form that submits and determines if we have met the criteria for each input and we have the ability to return a valid or invalid state. This is good!

Answer by James Esparza

A simple react and react native form validator inspired by Laravel validation. View on NPM » , A simple react form validator inspired by Laravel validation. , A simple react form validator inspired by Laravel validation.

npm install simple-react-validator --save

Answer by Kade Sheppard

What tools can I use to debug my app in Flutter?,Debugging What tools can I use to debug my app in Flutter? How do I perform a hot reload? How do I access the in-app developer menu? ,Platform-specific code

// JavaScript
function startHere() {
  // Can be used as entry point

Answer by Chana Knox

npm i react-native-google-places-autocomplete,Get your Google Places API keys and enable "Google Places API Web Service" (NOT Android or iOS) in the console. Billing must be enabled on the account.,

import React from 'react';
import { GooglePlacesAutocomplete } from 'react-native-google-places-autocomplete';

const GooglePlacesInput = () => {
  return (
      onPress={(data, details = null) => {
        // 'details' is provided when fetchDetails = true
        console.log(data, details);
        key: 'YOUR API KEY',
        language: 'en',

export default GooglePlacesInput;

Answer by Leila Black

The native HTML form validate has been disabled in a demo purpose so that you may see how validate.js works in action. , If you need an error not to be prefixed by the attribute add a leading ^ to the error and it won't be prepended. If you need to have a leading ^ but want the prefixing just write \^. , You can ignore inputs by adding the data-ignored attribute.

<script src="//"></script>
require(["validate.js"], function(validate) {
  // ...
$ npm install --save validate.js
var validate = require("validate.js");
$ bower install --save validate.js
$ component install ansman/validate.js