What ASCII characters are valid for Javascript variable names? [duplicate] - javascript

This question already has answers here:
What characters are valid for JavaScript variable names?
(12 answers)
Closed 7 years ago.
I've seen this other question, unfortunately the answers spend too much attention on Unicode and say nothing about normal ASCII characters.
I need to know which 7-bit ASCII characters (0..127) are valid in a Javascript identifier name.

According to this article, this is all about javascript variables :
The general rules for constructing names for variables (unique identifiers) are:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter
Names can also begin with $ and _
Names are case sensitive (y and Y are different variables)
Reserved words (like JavaScript keywords) cannot be used as names
You can use all ASCII codes. but you have to comply with above rules.

Related

Regex for password with specific restrictions [duplicate]

This question already has answers here:
Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
(42 answers)
Regular expression to check if password is "8 characters including 1 uppercase letter, 1 special character, alphanumeric characters"
(14 answers)
Closed 3 years ago.
I'm trying to come up with a regex that validates passwords. The restrictions are as follows:
Must be at least two of the following:
one lowercase [a-z],
one uppercase [A-Z],
one digit [\d],
one special character [!##\$%\^\&*)(+=._-].
must not begin or end with white-space but can contain white-spaces inside,
must be between 7 and 20 characters long.
So far, this is the last version of what I've come up with:
^(?=.{7,20}$)(?:(?=.*[\d!##\$%\^\&*\)\(+=._-])(?=.*[a-z])\S*|(?=.*[A-Z])(?=.*[\d!##\$%\^\&*\)\(+=._-])\S*|(?=.*[A-Z])(?=.*[a-z])\S*|(?=.*[\d)\(+=._-])(?=.*[!##\$%\^\&*\)\(+=._-])\S*)$
This works for all of the above except letting white-spaces inside. I've gone through multiple regex and this is the best one so far (but also the ugliest).
Edit: Thank you for the fast replies. Why these requirements are in place is beside the point. I know passwords would be more secure if all of the above were required. But as not all customers use password managers...
Now, why is this not a duplicate question? Because no other thread requires any two of the above. They simply start with requiring specific two, than adding another one and so on. This needs to be any two conditions.
Hey you can use below regex to fulfill your requirement
^(?=.\d)(?=.[A-Z])(?=.[a-z])(?=.[^\w\d\s:])([^\s]){7,20}$

Javascript regex to match equal number of consecutive 1 and 0 [duplicate]

This question already has answers here:
Recursive matching with regular expressions in Javascript
(6 answers)
Closed 4 years ago.
I want to write a regex which matches following scenarios,
10
1100
111000
11110000
// etc. consecutive 1 count should equal consecutive 0 count.
Is it possible to write a regex for this?
I suppose I could write, 1{n}0{n}, but it didn't work here: https://regex101.com/
May be this is not doable with regex?
I can of course do this with a loop. But I want to know if this is possible using regex.
Thank you!!!!
Theoretically the answer is no.
We can write regular expressions for strings that belong to regular languages.
Your case belong to a context free language.

Difference between toLocaleLowerCase() and toLowerCase()? [duplicate]

This question already has answers here:
In what JS engines, specifically, are toLowerCase & toUpperCase locale-sensitive?
(2 answers)
Closed 7 years ago.
What is the difference between these two ?
The description for the toLocaleLowerCase() mentions Converts a string to lowercase letters, according to the host's locale.
What is the host's locale ?
Definition and Usage as per w3schools
The toLocaleLowerCase() method converts a string to lowercase letters, according to the host's current locale.
The locale is based on the language settings of the browser.
Generally, this method returns the same result as the toLowerCase() method. However, for some locales, where language conflict with the regular Unicode case mappings occurs (such as Turkish), the results may vary.

email address validation in JavaScript using regular expression [duplicate]

This question already has answers here:
How can I validate an email address in JavaScript?
(79 answers)
Closed 7 years ago.
I'm currently trying to validate email address using regular expression in JavaScript. These are the requirements of the Email address:
The email field contains a user name part follows by "#" and a domain name part.
The user name contains word characters including hyphen ("-") and period (".").
The domain name contains two to four parts of alphabet characters word extension.
Each word extension is separated by a period (".") and the last extension must have two to three characters.
Among four requirements, the third one is most confusing to me. I will be very appreciate if someone can help me. Thank you.
I have tried the first answer in this page, but this answer accept even 5 or more extensions, so it doesn't meet my third requirement.
For Javascript, here is the regex you need which follows the RFC 5322 standard:
/^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*#([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
Side note: it is better to use a very weak regex (basically just matching the '#') and sending a confirmation email.

The difference between the javascript normal variable and the variable with a dollar sign [duplicate]

This question already has answers here:
Why would a JavaScript variable start with a dollar sign? [duplicate]
(16 answers)
Closed 9 years ago.
The question about javascript varabile with a dollar sign has been answered by a couple of times.
In short, the dollar sign plays as an identifier in javascript variable.
However, I was wondering are there more differences between the normal variable and the variable with dollar sign?
Behind the scene, will they have different memory location mechanism? or some other else.
Thanks for any reply. : )
A dollar sign has no specific meaning in JS. Usually it is used to distinguish jQuery objects from other variables but it's just a practice, not a rule.
The JS interpreter doesn't make any difference between "normal" variables and dollar variables; no different memory location or anything else, they are just common variables.

Categories

Resources