0

The definition below seems heavy for what it does. Can this be written more succinctly?

CREATE OR REPLACE FUNCTION "check_email"(email TEXT)
  RETURNS BOOLEAN AS $$
BEGIN
  RETURN email ~* '^[A-Za-z0-9._%+$-]+@[a-zA-Z0-9-]+([.][A-Za-z0-9-]+)+$';
END;
$$ LANGUAGE plpgsql;

I am not interested in shortening the regex, just the definition boilerplate.

0

1 Answer 1

1

You can use SQL instead of PLPGSQL language:

CREATE FUNCTION check_email(text)
RETURNS boolean AS $$
    SELECT $1 ~* '^[A-Za-z0-9._%+$-]+@[a-zA-Z0-9-]+([.][A-Za-z0-9-]+)+$';
$$ LANGUAGE sql;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.