gemvcnte / sims

2 stars 0 forks source link

Filter Non-Numeric Characters on Number Inputs #368

Open iampoll opened 5 months ago

iampoll commented 5 months ago

enrollment form

 <FormField
                control={form.control}
                name="lrn"
                render={({ field }) => (
                  <FormItem>
                    <FormLabel>
                      LRN (Learner Reference Number){" "}
                      <span className="text-destructive">*</span>
                    </FormLabel>
                    <FormControl>
                      <Input
                        placeholder="Enter your learner reference number"
                        type="text" // Convert type to text
                        {...field}
                        onChange={(e) => {
                          const value = e.target.value.replace(/[^0-9]/g, ""); // Replace any non-numeric characters with an empty string
                          field.onChange(value); // Update the form field value with the sanitized input
                        }}
                      />
                    </FormControl>
                    <FormMessage />
                  </FormItem>
                )}
              />
iampoll commented 5 months ago