clem
How to validate full string with Regex
I currently developing a rest API with elixir and plug.
I will like to validate user input to accept only letters, but when I use the regex, it only validates a letter, not the full string.
Example:
String.match?(“A”, ~r/[1]$/i) returns true, but when I try String.match?(“foo”, ~r/[2]$/i) returns false.
Any help, please?
Most Liked
NobbZ
Letters and numbers is broad… I consider ä a letter, do you? What’s about Chinese scripts? Or kyrillic? Greek? Persian numbers? Do you consider those as valid?
If you restrict to Arabic numerals and Latin letters in upper and lowercase it’s something like this:
~r/^[a-zA-Z0-9]+$/
2
zachgarwood
If you don’t mind underscores in there as well, you could use the \w “word characters” class, for example:
~r/^\w+$/
The \w class is equivalent to [A-Za-z0-9_].
1
Popular in Discussions
Hello everyone,
I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.:
redirect "/", UserController, ...
New
https://nitter.net/josevalim/status/1744395345872683471
https://twitter.com/josevalim/status/1744395345872683471
New
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
This is a post to discuss the new Phoenix LiveView functionality.
From Chris’s talk, it appears that they generate all HTML on the serve...
New
How We Replaced React with Phoenix
By: Thought Bot
New
I think this twitter post and youtube video didn’t get as much attention as I hoped
I am still new to Elixir, so can’t really judge
...
New
Erlang :list.nth simple, but 1 - based
nth(1, [H|_]) -> H;
nth(N, [_|T]) when N > 1 ->
nth(N - 1, T).
Elixir Enum.at … coo...
New
Other popular topics
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Hi all,
I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I’m trying to use Postgres...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New








