Develop ultra fast with Prismane 🎉

username

This validator checks if a string is a valid username.

Basic Usage

import { username } from "@prismane/core/validators";

console.log(username("spleafy")); // Will return null
console.log(username("xd"));
// Will return `This is not a valid username!`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      username: {
        value: "",
        validators: {
          username: (v: string) => username(v),
        },
      },
    },
  });

  return (
    <Form
      onSubmit={(e: any) => {
        handleSubmit(e, (v: any) => console.log(v));
      }}
      onReset={() => handleReset()}
      maw={300}
    >
      <TextField
        placeholder="Enter username: "
        label="Username:"
        {...register("username")}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

Parameters

NameTypeDescription
valuestringThe string that will be validated.
regExpRegExp / undefinedAn optional parameter that will overwrite the default regex used to match the string.