Solved

Validate Coldfusion Cfinput Textbox with Javascript

Posted on 2011-03-02
5
896 Views
Last Modified: 2012-05-11
How does one valideate a coldfusion cfinput type=text with javascript?
It is cfinput the same as a regular html input in the way it validates?
I would like to exclude characters like * in my text areas.
I have used keyCode values but I'm having a little trouble with thes text areas in Coldfusion.
0
Comment
Question by:FastEddie___
5 Comments
 
LVL 11

Assisted Solution

by:Brijesh Chauhan
Brijesh Chauhan earned 250 total points
ID: 35019100
Use a regular expression

<cfinput type="text" name="whatever" validate="regex" pattern="" ...... of course you need to get the correct regex so that it excludes * ....  
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 250 total points
ID: 35019150
You can use the same javascript on cfinput, this sounds like an onChange="" function call; something like this..

   onChange(checkEntry(this));

function checkEntry(obj) {
  var nStr = obj.value.replace(/[^\d\.]+/g, '')
  if (nStr != obj.value) {
       alert('Invalid characters');
       obj.select();
       return false;
       }
  return true;
}


Note you can also just change it to <input> unless you're using some CF specific parameters, they are interchangeable
0
 

Author Closing Comment

by:FastEddie___
ID: 35019996
Thank you.
0
 
LVL 13

Expert Comment

by:srikanthmadishetti
ID: 35020073
First of all is there any reason for you yo use cfinput  ,

with cfinput you can use the same javacript function  and call it on the event which you were calling for input

but if you want to write your custom validation stuff i strongly feel there is no need of cfinput unless you have a other strong reason for using it.

0
 

Author Comment

by:FastEddie___
ID: 35027980
@srikanthmadis
I'm not looking to replace what coldfusion has built in for form validation.
I am looking to enhance validiation as the user is typing by using onKeyPress.
That way I can check for certain characters and just not allow them to be typed in.

For example:

<cfinput ... onkeypress="return checkDateChars()" validate="date">

-----

function checkDateChars()
{ // 0-9, /, -
    if (    ((event.keyCode>47)&&(event.keyCode<58)) || (event.keyCode==45) || (event.keyCode==47)    )
    {
       return true;
    }
    else
       return false;
}

---

Along with the onkeypress I also would like to use the onBlur and run my own date validation functions so that the coldfusion validate="date" should never be called except when the user is trying to hack the site.

So what you're saying is that I can use all the colfdfusion tags from cfform (cfinput, cfselect,...) with regular javascript function calls???

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript/JQuery - HtmlEncode (?) Ajax Result 1 63
Hide Table in merge 3 29
forgetful about js objects 8 46
angular 2 problem setting an object inside a subscribe section 15 12
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question