This question already has answers here:
Validate phone number with JavaScript
(30 answers)
How to validate phone numbers using regex
(43 answers)
Javascript Regex - What to use to validate a phone number?
(9 answers)
Closed 5 years ago.
I am developing an Ionic app, and I need to validate an input field that may accept either a phone number, an email or a username. However, my application should be prepared to accept phone numbers from all over the world, which means that I should have a sort of generic solution to guarantee I am sending a valid number to a server.
I was checking how Facebook accept different phone formats to log in and I would like to make something similar. So I was wondering how I could achieve such thing. It allows me to log in using three different formats:
0 (11) 9 1234-5678 when typing 011912345678
(11) 9 1234-5678 when typing 11912345678
55 (11) 9 1234-5678 when typing 5511912345678
But as I am in Brazil, I believe it is easier to control it using a RegEx to validate only brazilian format numbers. But, how could I validate different phone numbers when I don't know where the user is? I'd like to hear from you guys if someone has achieved a solution for such problem. Thanks!
Edit: The main problem here is not using a RegEx to validate an international phone number format itself, but, how can I guarantee that even though the user may not type his International Country Code I still allow him to log in if he uses only his central office codes plus his subscriber number?
Related
This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 2 years ago.
I am attempting to create a regular expression for validating edu emails which may or may not have a sub domain. Some schools have emails like "example#hms.harvard.edu" while other schools have emails like "example#stanford.edu".
([0-9]|[a-z]|[A-Z])+#([0-9]|[a-z]|[A-Z])+([0-9]|[a-z]|[A-Z])\.edu$"
This is the current regular expression that I have but I am not well versed in these.
I am looking to create an expression that will validate emails with one domain and emails with a subdomain.
Any help would be appreciated. Thanks!
In most cases, /^[-\w.]+#[-\w.]+\.edu$/ should be enough.
The only problem with this solution would be, that it can also accept domains like hms..harvard.edu.
To prevent this, you could use this regex instead: /^[-\w.]+#([-\w]+\.)*[-\w]+\.edu$/
Edit: use \w instead of [0-9a-zA-Z_]
This should do the trick (modified from http://emailregex.com/ - referenced in How to validate an email address using a regular expression?):
/^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+edu))$/
This question already has answers here:
Large numbers erroneously rounded in JavaScript
(6 answers)
Closed 5 years ago.
I'm new in developing javascript apps, i have a doubt about a behaviour that i'm going to try to explain.
If i execute:
Number(5555555555555555);
Result: 5555555555555555
But if i execute:
Number(55555555555555555);
Result: 55555555555555550
Anybody can explain to me what is the reason of this? Thanks!!
If you need to work with such big numbers I would suggest you use some of the big integer libraries such as this. The reason this happens as far as I know is the way processors and memory work. It's no related to some "bug" in JS.
Integers (numbers without a period or exponent notation) are accurate up to 15 digits. Javacript simply adds zeros to keep the number accurate in terms of its digit length.
Documentation
I am trying to write a regular expression using javascript in order to validate data entry on an online database. I have attached a screenshot (Screenshot) of the page which is asking me to do this. The question I am asking is what is the weight? The validation I am trying to create is that it needs to be more than 24 kg. I am complete novice at JS (I have good experience with SQL) and have been reading developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions#Writing_a_Regular_Expression_Pattern and
www.w3schools.com/js/js_regexp.asp
I have tried a few things and tested them on rubular but to no avail.
Any advice would be much appreciated and in the meantime I will continue reading.
Many thanks,
Jenna
First off, this sounds the sort of situation for which a regular expression is not a reasonable choice for validation. Just comparing numbers would make much more sense.
However, a regular expression that would match a number greater than or equal to 24 would be:
/^(\d{3,}|[3-9]\d|2[4-9])$/
That is, it matches one of:
\d{3,} a number at least 3 digits long
[3-9]\d a number in the range 30 - 99
2[4-9] a number in the range 24 - 29
To match only greater than 24, just change the last alternative:
/^(\d{3,}|[3-9]\d|2[5-9])$/
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.
This question already has answers here:
Closed 10 years ago.
I would like to know how can we validate the Credit Card.
We have a script that allows the numbers like this
4444111122223333
I want the credit card validation to accept credit card number in this format (with white spaces.)
4444 1111 2222 3333
How it can be possible in JavaScript.
Thanks
A
try this
http://webwoman.biz/articles/Forms/NetscapeLibrary/ccnums.html
you could use regular expression to accomplish this task. take a look at this
and this short description of how to use regex in JavaScript