Showing posts with label Question And Answer. Show all posts
Showing posts with label Question And Answer. Show all posts

1/21/2018

Javascript Email format validation checker, check @ and dots

Question

I have done some searching on how to capture email address top level domain name dots and the number of @ sign. Most codes I found returned true if I enter like.

testemail@domain.com.co.uk.gov.info.org

I want a maximum of two dots and one @ sign only which caters domain such as:

domain.co.uk
domain.gov.info
domain.info.org

and so on.


Answer


Below is a code I created that will caters your email validation needs.


If you want to increase the number of accepted dots (.) just increase the value 4.

Hope it helps.

Display an array of texts using alert with line break in javascript

Question:


I have an array of string messages / texts and I want to display it using alert function in javascript. I managed to display them using join() function but I can not display them with line break at the end of each message / text and remove all the commas in between each text / message. Basically I want to display these texts like a list, below is my sample code:


Answer

What you did on your "test2" code is that you join all the texts and then added a break line at the end of it. Regarding the commas in between, you need to use the replace() function and regex to remove them. I believe what you are looking for this:

Copy and paste the code above in your browser console and press enter. It should display like a list.

10/20/2016

Show Remote MySQL Database Table List in Ubuntu

Question


I would like to know how to connect to MySQL database remotely and display the list of tables of my database. I tried doing it in my terminal through:

mysql -u USERNAME -pPASSWORD -h HOST_NAME DATABASE_NAME

and

mysql -u USERNAME -p PASSWORD -h HOST_NAME DATABASE_NAME

But nothing works, all it shows are the help options and variables.

Answer


All you need to do is use the mysqlshow instead of mysql like:

mysqlshow -u USERNAME -pPASSWORD -h HOST_NAME DATABASE_NAME

It should give you the list of table of your database like this:

Note:
 Password should be -pPASSWORD not -p PASSWORD.

Show Remote MySQL Database Table List in Ubuntu
MySQL Table list in Ubuntu terminal


10/05/2016

Unable to Access Localhost when running Webpack Dev Server

Question


In my sample React JS project I have a file called "webpack.config.js" and in it I specified the port where to run my localhost to 6000. My "webpack.config.js" looks like this:

When I try to run the webpack-dev-server it gives me the page "This site can't be reached".

Unable to Access Localhost when running Webpack Dev Server
Unable to Access Localhost when running Webpack Dev Server
Answer

I have encountered this issue as well and the cause of it is the port (in my experience). Granting the fact that you have setup everything properly (from react files, javascript files to node modules), something somewhere in your PC is already using the port 6000 so all you need to do is change the port to something else and it should work.