Pattern that restricts user to enter special characters for first character - angularjs

I have a requirement for an input field that should allow numbers, alphabets, and special characters like #,$,%,^ etc. But with only one condition the first character that I enter in the text box should not be a special character.
Example:
#Test123 --Invalid character
Test#123 --Valid character
T#est123% --Valid character
I tried this
ng-pattern="/^([a-zA-Z0-9]+)([a-zA-Z0-9 &()_+#&\-=\\|,.\/?\s]+)$/"
But not working.

Try this one
ng-pattern="/^[a-zA-Z0-9]+[^]*$/"
[a-zA-Z0-9]+ means one of alphabet or number and
[^]* means everything

Related

Why does the EXCEPT clause trim whitespace at the end of text?

I read through the documentation for the SqlServer EXCEPT operator and I see no mention of explicit trimming of white space at the end of a string. However, when running:
SELECT 'Test'
EXCEPT
SELECT 'Test '
no results are returned. Can anyone explain this behavior or how to avoid it when using EXCEPT?
ANSI SQL-92 requires strings to be the same length before comparing and the pad character is a space.
See https://support.microsoft.com/en-us/help/316626/inf-how-sql-server-compares-strings-with-trailing-spaces for more information
In the ANSI standard (accessed here section 8.2 )
3) The comparison of two character strings is determined as follows:
a) If the length in characters of X is not equal to the length
in characters of Y, then the shorter string is effectively
replaced, for the purposes of comparison, with a copy of
itself that has been extended to the length of the longer
string by concatenation on the right of one or more pad char-
acters, where the pad character is chosen based on CS. If
CS has the NO PAD attribute, then the pad character is an
implementation-dependent character different from any char-
acter in the character set of X and Y that collates less
than any string under CS. Otherwise, the pad character is a
<space>.
b) The result of the comparison of X and Y is given by the col-
lating sequence CS.
c) Depending on the collating sequence, two strings may com-
pare as equal even if they are of different lengths or con-
tain different sequences of characters. When the operations
MAX, MIN, DISTINCT, references to a grouping column, and the
UNION, EXCEPT, and INTERSECT operators refer to character
strings, the specific value selected by these operations from
a set of such equal values is implementation-dependent.
If this behaviour must be avoided, you can reverse the columns as part of your EXCEPT:
SELECT 'TEST', REVERSE('TEST')
EXCEPT
SELECT 'TEST ', REVERSE('TEST ')
which gives the expected result, though is quite annoying especially if you're dealing with multiple columns.
The alternative would be to find a collating sequence with an alternate pad character or a no pad option set, though this seems to not exist in t-sql after a quick google.
Alternatively, you could terminate each column with a character and then substring it out in the end:
SELECT SUBSTRING(col,1,LEN(col) -1) FROM
(
SELECT 'TEST' + '^' as col
EXCEPT
SELECT 'TEST ' + '^'
) results

Codename One - String replace with empty character

I like to normalize the phone numbers I get from the contacts in the local phone book. To do that, I want to remove any spaces, dashes, plus signs etc from the number.
CN1 only offers the String.replace(oldchar, newchar) function, instead of String operations. From this post,
How to represent empty char in Java Character class, this should be the way to go:
primaryPhoneNumber = primaryPhoneNumber.replace(' ', Character.MIN_VALUE);
however, this approach has several implications.
the char in the console output looks like a space, but its not. its a string terminator.
+49 234-63446
0 234 63446
when using this normalized string literal, including the Character.Min_Value in a database, the database query involving this string crashes:
Caused by: org.postgresql.util.PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00
How to properly remove spaces and other chars and replace them with a "nothing" character?
You can use:
String p = StringUtils.replaceAll(phone, " ", "");

how to ensure a user input contains at least one uppercase, lowercase, symbol, and number in ruby

I want to ensure that a password a user enters is at least 7 characters long and has at least one uppercase letter, one lowercase letter, one number, and one symbol.
The code seems to pass through the if loop until the symbol argument where it gets stuck.
puts "Please enter your desired password: "
password = []
pass_clear = ()
while pass_clear == (nil) do
password = gets.to_s.chomp
if password.length < 7
puts "Your password must contain at least seven characters."
elsif password.count("a-z") == password.length
puts "Your password must contain at least one uppercase character."
elsif password.count("A-Z") == password.length
puts "Your password must contain at least one lowercase character."
elsif password.count("!","#","#","$","%","^","&","*","(",")","_","-","+","=") < 1
puts "Your password must contain at least one symbol."
elsif password.count("0","1","2","3","4","5","6","7","8","9") < 1
puts "Your password must contain at least one number."
else
puts "Thank you, your account is complete."
pass_clear == 1
end
end
This is the output:
Please enter your desired password:
frank
Your password must contain at least seven characters.
Please enter your desired password:
frankie
Your password must contain at least one uppercase character.
Please enter your desired password:
Frankie
Your password must contain at least one symbol.
Please enter your desired password:
Frankie$
Your password must contain at least one symbol.
Please enter your desired password:
And it continues looping through the symbol stage regardless of how many symbols there are.
How can I ensure these symbols are recognized so the loop can finish?
You are quoting each of the symbols which is incorrect. You also have to escape the - and ^ characters
password.count("!##$%\\^&*()_\\-+=")
works for me in this example.
You'll also need to use a range for your numbers like:
password.count("0-9")
The - character is used for the ranges like "a-z" so it has to be escaped, the carat ^ is used to negate a count so:
password.count("^a-z")
would return a count of everything that wasn't in the range of a-z.
This can come in handy as you may want to prevent certain characters from being in your password strings. You could do something like:
password.count("^a-zA-Z!##$%\\^&*()_\\-+=0-9)
This would count any other characters outside what you've defined so you would want to get a zero return value to know they didn't use any forbidden characters.
Some further clarification on ranges in count(). The term "range" should not be confused with the Ruby class "Range". The class of Range uses ".." or "..." for the intervening items. In the count() method the range being considered is the ASCII range from the first character's ASCII number to the second character's ASCII number. That's why in my original typo of A-z it was counting ASCII 65 ("A") to ASCII 122 ("z") which happens to include the characters ASCII 92 to 96 which are not letters but \ ] ^ _ `
One option is to use a regex that contains four positive lookaheads, all of which operate from the beginning of the string.
R = /
(?=.*\p{Ll}) # match lowercase letter
(?=.*\p{Lu}) # match uppercase letter
(?=.*\d) # match digit
(?=.*[#{Regexp.escape("!##$%^&*(,)_+=-")}]) # match special char
/x # free-spacing regex def mode
def password_ok?(str)
str.match?(R)
end
password_ok? "aA1#" #=> true
password_ok? "A1#" #=> false
password_ok? "a1#" #=> false
password_ok? "aA#" #=> false
password_ok? "aA1" #=> false

Format field for 3 numerical digits with optional letter

I have a very large list of assets all with room numbers. All room number are 3 digits. Room number on the bottom floor begin with leading zeros (001, 002, etc). However, some rooms have letters after them (020A, 020B).
How can I format my field in Microsoft Access to display leading zeros but also accept that some rooms have a letter after the 3 digits?
A text formatted field will display any entered data as a string literal, i.e. no matter what combination of numbers and letters you enter it will keep those data as typed. So 001 and 020A would both be accepted.

Regex for one column that has numbers and letters but not one or the other

I am attempting to search a column that contains alphanumeric ids in it but want to write a query that returns records with letters and numbers but not one or the other.
i.e Acceptable: jjk44kndkfndFF
i.e Not acceptable: 223232323232 or aajnfdskDFdd
So far I have:
where PATINDEX('%[^a-zA-Z0-9 ]%',columnInQuestion)
This returns all alphanumeric records. Any direction appreciated
I think you need three predicates in the WHERE clause:
WHERE (columnInQuestion NOT LIKE '%[^a-zA-Z0-9]%') AND
(PATINDEX('%[a-zA-Z]%', columnInQuestion) <> 0) AND
(PATINDEX('%[0-9]%', columnInQuestion) <> 0)
First predicate (columnInQuestion NOT LIKE '%[^a-zA-Z0-9]%') is true if columnInQuestion contains only alphanumeric characters
Second predicate (PATINDEX('%[a-zA-Z]%', columnInQuestion) <> 0) is true if there is at least one alphabetic character in columnInQuestion
Third predicate (PATINDEX('%[0-9]%', columnInQuestion) <> 0) is true if there is at least one numeric character in columnInQuestion
It can be done with just one regexp:
^[a-zA-Z0-9]*([a-zA-Z][0-9]|[0-9][a-zA-Z])[a-zA-Z0-9]*$
It starts and ends with 0-x legal chars.
And somewhere there is a switch from a letter to a digit or from a digit to a letter.

Resources