Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6212

Formik Validation for React Native Input Field

$
0
0

I am using native base's input field and am trying to validate it using Formik and Yup. However, no validation is happening so far. It doesn't show any errors even if I type alphabets.

const initialValues: FormValues = {    phoneNumber: '',  };  const validationSchema = phoneNumberValidationSchema;  const handleSubmit = (    values: FormValues,    helpers: FormikHelpers<FormValues>,  ) => {    console.log('Verifying');  };

This is from my return function:

<Formik                initialValues={initialValues}                onSubmit={handleSubmit}                validationSchema={validationSchema}>                {({                  handleChange,                  handleBlur,                  handleSubmit,                  isSubmitting,                  values,                }) => (<View><Item><Input                        placeholder="Phone Number"                        onChangeText={handleChange('phoneNumber')}                        onBlur={handleBlur('phoneNumber')}                        value={values.phoneNumber}                      /></Item><View ><Button rounded ><Text >                          Add{''}</Text></Button></View></View>                )}</Formik>

Schema:

const phoneNumberValidationSchema = yup.object().shape({    phoneNumber: yup      .string()      .label('phoneNumber')      .required('Bitte gebe deine Handynummer ein.')      .matches(/^[0-9]*$/, 'Bitte nur Ziffern eingeben.'),  });

What am I missing?


Viewing all articles
Browse latest Browse all 6212

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>