Here we are going to write a regular exprestion for Password to check the condition like , password must contain at least one number,one capital letter and one special character.
This will check the string contain at at least one number,one capital letter and one special character,
Here i am going to show examples with Javascript function ,
We can write a function in javascript as below
function validatePassword(str)
{
// patter to match : Atleast one number ,one capital letter, one special charector
var reg = /^(((.*\d.*[A-Z].*[!@#$%^&*? ~].*))|(.*[A-Z].*\d.*[!@#$%^&*? ~].*)|(.*[!@#$%^&*? ~].*[A-Z].*\d.*)|(.*[!@#$%^&*? ~].*\d.*[A-Z].*))$/;
if (reg.test(str)) {
return true;
}
else {
return false;
}
}
and we can pass the string as function argument “str”, It will return if it matches the condition else it will return false.
To allow integer only in text field we can use the following jquery function .
We can write below code inside a document.ready function and give the class “integer-allowed” for the text box we needed.
Today we are going to learn about force downloading prompt in PHP.
While i am doing my projects, i had a requirement for file download, File type will be changed, So i made a research on this and made simple useful script which can be use any where to prompt download by giving path and file name . Let us create a function download_file and pass full file path and filename , we can use third argument to mention the MIME Type of file
Next we are going to set mime type if we already pass the MIME type into function it will take that MIME ,else we are going to use a function pathinfo to retrieve the extension of file and we will compare with already created array to get content type
lastly we are going to read each line by line and print that as shown below.
$chunksize = 1 * (1024 * 1024);
$bytes_send = 0;
if ($sourceFile = fopen($sourceFile, 'r')) {
while (!feof($sourceFile) &&
(!connection_aborted())
) {
$buffer = fread($sourceFile, $chunksize);
print($buffer); // is also possible
flush();
}
fclose($sourceFile);
} else {
header("HTTP/1.1 505 Internal server error");
return;
}
That is it !!!!! Now we can have a look, How we can read the file using created function We can make a path file and the name we want to give while downloading and pass to function . It will download prompt for file. example for reading file and download prompt
Today we are going to learning Hello world in Angularjs .
AngularJS, a JavaScript M-V-W (Model-View-What ever) framework developed by a Googler and supported by Google.
if you are using jquery in your application , Angular will amaze you. We are writing very less code in jquery , angular will minify it again !!
Angularjs is giving amazing support to AJAX and we can make a very interactive website with angularjs.
Angular can be defined as a client side javascript framework adding intractivity to HTML. As i mention on top angular is MVW framework
which means ,model view and what ever. There are many software architecture patterns like MVC,MVP (Model View-presenter).
But angular doesn’t care about software architecture . A basic concept of MVW is that all definitions are associated with a named Module.
Angular come with a rich set of APIs to defined and this modules can be linked together by dependency injection.
Hello world in Angular js
let us try a simple hello world in angular js
in order to write angular js in our application we need to include angular js in our HTML page,
We can download and include or we can directily include from CDN
Here i am including
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.16/angular.min.js"></script>
<div ng-app>
Write some text in textbox:
<input type="text" ng-model="text" />
<h1>Hello {{ text}}</h1>
</div>
Note that we didn’t write a single line of JavaScript and still this example works like a charm! Live example
Write some text in textbox:
Hello {{ text}}
Let us check step by step
Here i had included “ng-app” after. This tell angular that , angular need to monitor this section if we want angular to monitor one part of our application we can wrap with a div and we can write “ng-app” there. So angular will only monitor that part.
Now we defined ng-model=”text” in text box ng-model bind the state with model value.if we made any changes in the
textbox it will reflect {{text}}.
This is twoway binding. Angular will always keep an eye in ng-model defined and when ever it is changing ,
it will reflect on the ng-model value in double curly braces. .
This is a simple hello world application in angularjs
Today we are going to learning Angularjs, just try out What I found, an easier and simple way to write simple form submit in angularjs with php.
angular js with php form submission
We can make a HTML form to submit and save to database,
Here we are going to include 2 js files; one is Angularjs library and another one formjs.js which we will be using in writing controller of our form.
Let us dig deep into the form
We will be adding ng-app=”formExample” after the html tag -ng-app tells the angular, this block needs to be watched by the angular module.
After that we need to add the controller to form tag like ng-controller=”formCtrl”
– we are going to define formCtrl in formjs.js to tell what are the action need to do with that form
Lastly we will add ng-click=”formsubmit(userForm.$valid)”
On clicking the button, it will go to formsubmit function and we will pass the validation rules as parameters. We will use native $valid function to validate the form.
Now we will have a look on the javascript (formjs.js) file
First we are going to define the module as “formExample”.(We have already included in html as mentioned above).
Next to that we will define our controller with two dependency, ‘$scope’ and ‘$http’. $scope is for current scope and $http for ajax submission.
Later we will define formsubmit function and we will pass the validation status as parameter.
Now we will fetch all the values from the form and validate, on successful validation it is send to submit.php as json data. If form validation fails, it will show an alert message.
Below is the query to save data to database .
Here I am just printing all the values which we will get from the form for illustration.
php submission form