How to add Regular Expression in Javascript? - angular-reactive-forms

I have a Requirement for password pattern as below
=> Password Should contain atleast 1 upper case character
=> Password Should contain atleast 1 lower case character
=> Password Should contain atleast 1 number
=> Password Should contain atleast 1 special character !#$&

Related

Laravel password strength validation

Is there any better way to validate password, I know below
'password' => 'required|
min:6|
regex:/^.(?=.{3,})(?=.[a-zA-Z])(?=.[0-9])(?=.[\d\x])(?=.[!$#%]).$/|
confirmed',
Here is a much better solution from the Laravel Docs:
use Illuminate\Validation\Rules\Password;
// Require at least 8 characters...
Password::min(8)
// Require at least one letter...
Password::min(8)->letters()
// Require at least one uppercase and one lowercase letter...
Password::min(8)->mixedCase()
// Require at least one number...
Password::min(8)->numbers()
// Require at least one symbol...
Password::min(8)->symbols()
You can try Laravel docs as well
Neither Just try below,
'password' => [
'required',
'string',
'min:10', // must be at least 10 characters in length
'regex:/[a-z]/', // must contain at least one lowercase letter
'regex:/[A-Z]/', // must contain at least one uppercase letter
'regex:/[0-9]/', // must contain at least one digit
'regex:/[#$!%*#?&]/', // must contain a special character
],

How to allow more characters in the validation of an email field?

I'm having a problem validating the length of an email in Laravel 5.4.
In the migration I created the email field by default, and it was done correctly in DB as varchar (191) utf8mb4_unicode_ci.
In the frontend there is no problem with validation, but in backend it only allows up to 73 characters.
In Controller on save and update methods, I tried:
$this->validate($request, [
// ...
'email' => 'nullable|email',
// ....
]);
$this->validate($request, [
// ...
'email' => 'nullable|email|max:191',
// ....
]);
View form input:
{!! Form::label('email', 'Email:') !!}
{!! Form::email('email', null, ['class' => 'form-control' . ($errors->has('email') ? ' is-invalid' : ''), 'maxlength' => 191]) !!}
#if ($errors->has('email'))
<span class="invalid-feedback">{{ $errors->first('email') }}</span>
#endif
This passes the validation (73 characters):
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa#test.com
but this, or longer ones, do not pass the validation (74 characters):
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa#test.com
(also I tried other characters, not just aaa, just in case it's not the lenght with no luck)
What am I doing wrong?
RFC specifications for email and what is technically valid within one.
An e-mail address consists of local part and domain separated by an at sign (#) character (RFC 2822 3.4.1).
The local part may consist of alphabetic and numeric characters, and the following characters: !, #, $, %, &, ', *, +, -, /, =, ?, ^, _, `, {, |, } and ~, possibly with dot separators (.), inside, but not at the start, end or next to another dot separator (RFC2822 3.2.4).
The local part may consist of a quoted string—that is, anything within quotes ("), including spaces (RFC 2822 3.2.5).
Quoted pairs (such as #) are valid components of a local part, though an obsolete form from RFC 822 (RFC 2822 4.4).
The maximum length of a local part is 64 characters (RFC 2821 4.5.3.1).
A domain consists of labels separated by dot separators (RFC1035 2.3.1).
Domain labels start with an alphabetic character followed by zero or more alphabetic characters, numeric characters or the hyphen (-), ending with an alphabetic or numeric character (RFC 1035 2.3.1).
The maximum length of a label is 63 characters (RFC 1035 2.3.1).
The maximum length of a domain is 255 characters (RFC 2821 4.5.3.1).
The domain must be fully qualified and resolvable to a type A or type MX DNS address record (RFC 2821 3.6).
So in conclusion if you would want to use a longer one you should add your custom email rule which will avoid some of this checks.

What to use as a delimiter so I can detect the original inputs. Any good ideas. Ruby

I have an Encoder (using openssl) that can encrypt and decrypt strings like so:
new_addresses
=> ["fasfds", "someaddress", "123- this is also a valid address"]
[8] pry(#<Sinatra::Application>)> Encoder.encrypt(new_addresses.join(' '))
=> "55C2FB253468204EA9D3F5CE6D58DC4088BD52731B90B9C0C8EB5FE7FA1CD4E7B41F0A84DC46C69E09A10DC1931C6A976A58E29C"
[9] pry(#<Sinatra::Application>)> enc=_
=> "55C2FB253468204EA9D3F5CE6D58DC4088BD52731B90B9C0C8EB5FE7FA1CD4E7B41F0A84DC46C69E09A10DC1931C6A976A58E29C"
[10] pry(#<Sinatra::Application>)> Encoder.decrypt(enc)
=> "fasfds someaddress 123- this is also a valid address"
The issue I have here is that I have no idea which were the original 3 addresses. The new_addresses which are merely params that come in from a form are an array separated by commas. But when I join them together and encode it, I lose the comma delimiter and the array structure when I decrypt it so I have no idea what were the original 3 addresses. Any ideas on what I can do so that after I decrypt the string, I still can detect on what the original 3 addresses are.
These are valid characters in an address:
' '
-
_
^
%
$
#
...
really any characters.
It looks like your encryption algorithm uses only the characters 0-9 and A-Z. In that case, you can use any character that is not one of those characters to join() your encrypted strings together, for instance "-":
encrypted_str = "55C2FB253-3F5CE6D58DC4-B5FE7FA1CD4E7"
encyrpted_pieces = encrypted_str.split '-'
decrypted_pieces = encrypted_pieces.map do |piece|
Encoder.decrypt piece
end
On the other hand, if you want to join your strings together first, then encrypt the combined string, you can use the non printing ascii character named NUL to glue the pieces together. NUL's ascii code is 0, which can be represented by the hex escape \x00 inside a String:
decrypted_str = "fasfds\x00someaddress\x00123- this is also a valid address"
puts decrypted_str
pieces = decrypted_str.split "\x00"
p pieces
--output:--
fasfdssomeaddress123- this is also a valid address
["fasfds", "someaddress", "123- this is also a valid address"]
Magic.
Of course, the separator character should be a character that won't appear in the input. If the input can be binary data, e.g. an image, then you can't use \x00 as the separator.
These are valid characters in an address:
' '
-
_
^
%
$
#
...
Note that you didn't list a comma, which would be an obvious choice for the separator.

validation on exact length of numeric field in laravel 5

I have numeric field i want to validate on exact fill 4 digits.
like: 1234, 4567,1245
but these invalid inputs:
like: 123, 346, 45m6, 34567
what I am trying:
'last4digits' => 'numeric|between:4,4',
You are looking for the digits rule. From the docs:
The field under validation must be numeric and must have an exact length of value.
'last4digits' => 'digits:4'
in general case ,say, for a string with arbitrary characters:
'last_not_only_4_digits' => 'size:4'

Find any two periods and any non-digit character in regex string

I'm close, I just need a few tips on getting this correct.
Essentially I want to return true if I have the string 1.0, but return false if I have the string 1..0 or ANY character other than numbers.
So I need to match any character other than numbers but I can also match 2 or more periods.
EX:
1.0 => true
2.000004 => true
foobar => false
2..0 => false
2 => true
2.0.0.0.0 => false
I currently have been toying with this: /[a-zA-Z]|.{2,}/
my translation is that it matches any letters, or any 2 periods..
It works, but it only matches 2 consecutive periods, so the following happens
2.0.0.0.0 => true (I want to be false, as in I want to match this)
I would like to use \D instead of [a-zA-Z] to potentially avoid any strange ASCII characters but a period is in the subset of \D but not in [a-zA-Z]
Any tips? Thanks!
I've tested all your options
^\.{1}?[0-9]*\.{1}?[0-9]+$
http://rubular.com/r/5ll1Grhy6H
If you need negative numbers:
^[.-]{1}?[0-9]*\.{1}?[0-9]+$
http://rubular.com/r/LLOjq1pIUY
Here is an opposite approach:
/\.{2,}|[^\d\.-]|(\d\.){2,}|\.\z|.-/
This regex will find "incorrect" strings, that contain:
two or more dots close to each other
characters that are not: digits, dot, dash (for negative numbers)
two or more groups "digit-dot" (like in 2.0.0.0.0)
dot as a last character
dash not in the first position
All strings that return true in this comparison
string !~ /\.{2,}|[^\d\.-]|(\d\.){2,}|\.\z|.-/
should be valid numbers (floats or integers)

Resources