Tuesday, April 28, 2015

Regular expression in JavaScript

In JavaScript regular expressions are object. Regular expressions are patterns used to match character combinations in strings.

Example 1
i for case-insensitive search


Example 2


Example 3
^ indicates the beginning of the string. Using a ^ meta character requires that the match start at the beginning.
\d indicates a digit character and the {5} following it means that there must be 5 consecutive digit characters.
$ indicates the end of the string. Using a $ meta character requires that the match end at the end of the string.


Example 4


Example 5


Example 6


Example 7
Matches end of input.
For example, /t$/ does not match the 't' in "eater", but does match it in "eat"


Example 8


Example 9


Example 10
The \w meta character is used to find a word character.
A word character is a character from a-z, A-Z, 0-9, including the _ (underscore) character.


Example 11
validation password
password can contain digits
password can contain character lower or upper case
password must have length between 5 to 10
password can contain _ (underscore)


Example 12
validation password
password can contain digits
password can contain character lower or upper case
password must have length between 5 to 15
password can contain !@#$%^&*_ (special character)


Example 13
validation password
password should contain atleast one digit
password should contain atleast one special character
password can contain character lower or upper case
password must have length between 5 to 15


Example 14
validation password
password should contain atleast one digit
password should contain atleast one special character
password should contain atleast one upper case latter
password can contain character lower or upper case
password must have length between 5 to 15


Example 15
validation
atleast one number
atleast one lower case latter
atleast one upper case latter
must have more than 5 length

Wednesday, April 22, 2015

Adding an existing project to GitHub

1. Go to the project directory and run the command 'ls -al' to see .git directory exist in your project or not, if it is not exist then run the below command.

git init

You can see .git directory is created in your project directory.

2. Then by running 'git status' command, you can see the files. You have to add these files to git

git add .

3. then you have to commit

git commit -am "my first commit"

4. Now you have to add remote to your project but first you need to create repository in Github.
Go to Github and create repo.

5. Now you have to add a remote, you can see the remote by 'git remote -v' command.

git remote -v
// display empty result

You can add remote by following command.

git remote add origin address_of_remote_repo

Now run

git remote -v
// you will see the remote url

6. Now you need to pull master from your project.
Run below command

git pull origin master

7. Last you need to push your files to Github repo.

git push -u origin master

Sunday, April 19, 2015

$http service in AngularJS

$http service in AngularJS is used to send AJAX request.

var promise = $http(config);

Here the config parameter is a JavaScript object which can contain the following properties

1. Method
2. URL
3. Params
4. Headers
5. Data
6. Timeout
7. Cache
8. TransformRequest
9. TransformResponse
10. Withcredentials

1. Method : The method property can be GET, POST, PUT, DELETE. The method property type is String.

2. URL : URL of AJAX call. The URL property type is String.

3. Params : The Params property is used to set any additional request parameters to be appended to the URL query string. The Params property is a JavaScript object.

4. Headers : The header property is used to set any additional HTTP headers you want to sent to the server. The header property is a JavaScript object.

5. Data : The data property contains data to be sent to the server. Only PUT and POST request contains data property. The data property type is a object.

6. Timeout : The timeout property is used to set the timeout  for the AJAX call, when the timeout limit is reached, the AJAX call is aborted. The timeout is specified in milliseconds

7. Cache : The cache property is used to enable XHR GET request caching.

8. TransformRequest : The transformRequest property is used to set a function which can transform the request object before it is sent to the server.

9. TransformResponse : The transformResponse property is used to set a function which can transform the response sent back from the server, before it is passed to your application.


$http(config) return a "promise" object. This promise object has two functions success() and error(). Each of these two functions take a callback function as parameter. If the AJAX request succeeds, the callback function passed to the success() function is executed. if the AJAX request fails, the callback function passed to the error() function is executed.

Both functions take the following parameters :

1. Data
2. Status
3. Headers
4. Config

1. Data : The data parameter is the JSON object returned by the server.

2. Status : The status parameter is the HTTP status code returned by the server.

Format is

GET Request Example

PUT Request Example

POST Request Example


DELETE Request Example