PhoneFormatter Class needs work

PROBLEM: The PhoneFormatter class chokes on non-numeric
characters.
when you try and format this string "(415) 555-1212". It
throws an error.
right at the beginning of the "format" function, the class
checks to see if the incoming string is a number with this code:
if (!value || String(value).length == 0 ||
isNaN(Number(value)))
error = defaultInvalidValueError;
return "";
What it should do is strip all the non-numberic characters
from the input string THEN run that error check. Instead it just
returns "";
Also, the code in that proc is really long(old) when some
pattern matching using RegEx could cut that code down to 3-4 lines.
I think that Class should be re-written.
so you have to strip all the non-numeric characters from the
string before you send it to the format() function.
use this:
public function stripToNumbersOnly(inputStr:String):String
// rips the non-numeric characters from a string
// in preparation for PhoneFormatter (which sucks)
var regex:RegExp = /\D/g;
var retStr:String = inputStr.replace(regex,"");
trace ("stripping: " + inputStr+ " = " + retStr);
return retStr;
SURE WOULD BE NICE TO BE ABLE TO POST CODE IN THIS
FORUM.....

Good Point! I ran into this issue today when formatting the
data entered by the end user.
<mx:TextInput x="24" y="228" id="usr_phone" width="278"
fontSize="9" toolTip="Enter Your Phone Number"
focusOut="formatPhoneNumber(usr_phone)"/>
public function formatPhoneNumber(item:TextInput):void
var remString:RegExp = /\D/g;
var phoneFormatter:PhoneFormatter = new PhoneFormatter;
phoneFormatter.validPatternChars = "#-() ";
phoneFormatter.areaCode = -1;
phoneFormatter.areaCodeFormat = "(###)";
phoneFormatter.formatString = "(###) ###-####";
var fString:String = item.text.replace(remString, '');
item.text = phoneFormatter.format(fString);
}

Similar Messages

  • Can't get extended class to work with asbstract class

    I am having trouble working an extended class to work with my base abstract class. I keep getting this error message: "Fiction.java:4: invalid method declaration; return type required" public FictionBook()" Can someone give me some advice and or guidance on what I need to do? Thanks.
    Here is my abstract class:
    import javax.swing.*;
    public abstract class Book
         protected String bookTitle;
         protected double bookPrice;
         public abstract double setPrice();
    public Book()
              setBookPrice();
    public double getBookPrice()
              return bookPrice;
    public abstract void setBookPrice();
    Here is the extended class that I have:
    import javax.swing.*;
    public class Fiction extends Book
         public Fiction()
              super();
              setBookPrice();
         public void setBookPrice();
              bookPrice = 24.95;
         public String toString()
              return("Fiction Book Price is $" + bookPrice);
    }

    Fiction.java:2: Fiction is not abstract and does not override abstract method setPrice() in BookThis one is pretty straightfoward: Book declares an abstract setPrice() method. In effect is promises "every concrete subclass of Book will define an implementation of setPrice()". But your Fiction class does not do this - it does not give an implementation of setPrice() even though as a Book it is required to do so. That is what the compiler is complaining about.
    Fiction.java:6: call to super must be first statement in constructorThis one is slightly cryptic. If you use super() it must be as the first line of a constructor. You are using it as the first line of Fiction() so that looks OK - until you realise that Fiction() is not a constructor! That's because you declare it as a method returning void. Remove the "void" and the compiler will recognise it as a constructor and will be happy about your use of super().
    Edited by: pbrockway2 on Sep 13, 2008 12:13 PM
    Just a general point: it might be worth writing very brief comments for your abstract class to say what the methods are supposed to do. It isn't really clear what setBookPrice() is supposed to do given that it isn't passed any argument. Likewise setPrice(), how does it differ from setBookPrice()? what is the double value that it returns?

  • Two class needs to be extends, So I need some  WorkAround ...

    I have a Simple Question
    for accessing SAP PI MAPPING API in ECLIPSE .
    I need to extend one class AbstractTransformation ....
    similary for getting SAX Parser functionalty in ECLIPSE , I need to extend class DefaultHandler..
    So How to Handle this Case : Two class needs to be extends and I know only one class can be extend .
    So JAVA GURUS , I need some workaround .
    Regards
    PS

    Hi,
    First of all Java does not allow multiple inheritance ie u can extend from only one base class.
    work around :
    write two seperate java class say
    1. myJavaMapping.java which extends AbstractTransformation.
    2. mySaxParser.java which extends DefaultHandler
    And now create an object of mySaxParser in ur myJavaMapping class(see below code).
                    mySaxParser parser = new mySaxParser(out);                             //Out is the outputstream
              SAXParserFactory factory = SAXParserFactory.newInstance(); //standard class
              try
                   SAXParser saxParser = factory.newSAXParser();              //standard class
                   this.out = out;
                   saxParser.parse(in, parser);                                                 //begin parsing                                                                               
    // in is inputstream object & has input XML
              catch(Exception e)
                   e.printStackTrace();
    Hope it is clear,
    Anand

  • Is anyone else having email problems such as apps exiting in the middle of an email? It may be a wireless issue. I use First Class for work and yahoo email for personal. I will be in the middle of typing a long email and the app just quits, all data lost.

    Is anyone else having email problems such as apps exiting in the middle of an email? It may be a wireless issue. I use First Class for work and yahoo email for personal. I will be in the middle of typing a long email and the app just quits, all data lost.

    Have you tried restarting or resetting your iPad?
    Restart: Press On/Off button until the Slide to Power Off slider appears, select Slide to Power Off and, after the iPad shuts down, then press the On/Off button until the Apple logo appears.
    Reset: Press the Home and On/Off buttons at the same time and hold them until the Apple logo appears (about 10 seconds). Ignore the "Slide to power off"

  • Error Message: A main Java class needs to be specified to run the program.

    Hi,
    I am adding a program object to cms using java program, and trying to run it. I am getting an error message like
    Error Message: A main Java class needs to be specified to run the program.
    Could you please help me on this., please find the pasted program object pasted below
    public class MoveReports   {
    public void run(IEnterpriseSession enterpriseSession, IInfoStore infoStore,
                   String[] args) throws SDKException {
        int objectSize = ;
        String cms = "";
         String username = "";
         String password = "";
         String auth = "";
        try {
              ISessionMgr sm = CrystalEnterprise.getSessionMgr();
             enterpriseSession = sm.logon(username, password, cms, auth);
             IInfoStore oInfoStore=(IInfoStore)enterpriseSession.getService("", "InfoStore");
                 IInfoObjects iObjects = null;
                   iObjects = oInfoStore.query("Select * from CI_INFOOBJECTS where SI_PARENTID = 44104 AND SI_PROGID LIKE '%CrystalEnterprise.Excel%'");
                   // Getting total number of reports
                   objectSize = iObjects.size();
                   if(objectSize > 0)
                        for (int count = 0; count < objectSize; count++)
                             IInfoObject obj = (IInfoObject) iObjects.get(count);
                             // Specify the Destination parent Id to move the reports
                             obj.setParentID(44102);
                        oInfoStore.commit(iObjects);
                        System.out.println("Reports Moved Successfully");
                   else
                        System.out.println("Reports Not Available");
             catch (SDKException e) {
                 e.printStackTrace();
                 System.out.println("Error : " + e.getMessage());
    Thanks&Regards
    Damodar
    Edited by: Damodaram B on Nov 2, 2009 1:29 PM

    There's couple of things at issue here - you've not specified the proper interface (IProgramBase or IProgramBaseEx), and the program job server can't find the class in question (a deployment issue).
    You may want to open a support ticket with SAP.
    Sincerely,
    Ted Ueda

  • Why do we need Work Table in ODI???

    Hello All,
    Please help me on this..
    Why do we need Work table in ODI???
    Why ODI is creating c$_0table_name (work table)?
    Thanks
    Ravikiran

    Hi,
    this is the standard "Load Data" from LKM SQL to SQL
    +<%for (int i=odiRef.getDataSetMin(); i <= odiRef.getDataSetMax(); i++){%>+
    +<%=odiRef.getDataSet(i, "Operator")%>+
    select     <%=odiRef.getPop("DISTINCT_ROWS")%>
    +     <%=odiRef.getColList(i, "", "[EXPRESSION]\t[ALIAS_SEP] [CX_COL_NAME]", ",\n\t", "", "")%>+
    from     <%=odiRef.getFrom(i)%>
    where     (1=1)
    +*<%=odiRef.getFilter(i)%>*+
    +*<%=odiRef.getJrnFilter(i)%>*+
    +<%=odiRef.getJoin(i)%>+
    +<%=odiRef.getGrpBy(i)%>+
    +<%=odiRef.getHaving(i)%>+
    +<%}%>+
    as you can see in C$_ you could have some filtered data. If you have got a source table containing invoicing (10kk rows) you could filter last_update column and obtain 1k rows for example and copy only this tiny subset.

  • Generic Java class for working with Context Nodes

    Hi,all
    I would like to write generic Java class for working with Context Nodes:
    populating node,
    add element to node,
    update node element,
    remove node element
    Any ideas how can I do it?

    Hi,Armin
    Thanks for your answer.
    I have many nodes with the same structure,but different data.
    I don't want to work with each one of them individually.
    This is the main reason.
    Regards,
    Michael
    Any ideas?

  • Need help locating a Polygon class that works in double precision

    The title says it all even though a class with floating points would be good too. ty :)

    You could always make your own polygon class that encapsulates
    java.awt.geom.Line2D
    Line2D has float and double implementations

  • Function module to get holiday class from work schedule for current day

    I need to determine what the public holiday class value is for the current day in a user exit.  Is there an SAP function module that can return me this data?  This would be the information that is displayed when pressing the work schedule button from infotype 0007

    Function module HOLIDAY_CHECK_AND_GET_INFO is closer to what I need.  This function module returns an X if the day is a holiday.  I will create a Z program and instead of returning an X for a holiday I will return the THOL-KLASS (holiday class) value.

  • How do I get external classes to work in AS3? Sample included.

    I'm trying to make this work, and something basic must be missing.  Its straight out of the Adobe help file example.
    CS4, Actionscript 3
    Here's what I'm doing:
    1.  create an .as file and name it "HelloWorldExample"
    2.  Put the script below in it and save it.
    3.create a new .fla file and save it to the same directory.
    4.in that .fla file, put "HelloWorldExample" in the Document properties Class field
    5. Save it and run the movie.
    I get a white screen.  Nothing.  I've tried a few other examples as well, but I haven't been able to get ANY external .as files to run. This is the simplest one.
    Do I need to import them or call them in some way other than step 4?
    Did I miss something?
    package
        import flash.text.engine.*;
        import flash.display.Sprite;
        public class HelloWorldExample extends Sprite
            public function HelloWorldExample()
                var str = "Hello World! This is Flash Text Engine!";
                var format:ElementFormat = new ElementFormat();
                var textElement:TextElement = new TextElement(str, format);
                var textBlock:TextBlock = new TextBlock();
                textBlock.content = textElement;
                var textLine1:TextLine = textBlock.createTextLine(null, 300);
                addChild(textLine1);
                textLine1.x = 30;
                textLine1.y = 30;

    As long as you have your class paths set properly, it's better to have your .as files located in a different loc than your .fla. What if you want to use the same class in different .fla files? Are you going to copy it into every project folder? That sort of defeats the purpose of using classes then, because if you change it you have to change it in various places. Not good. Not OOD.
    So: Edit > Preferences > AS3 Settings - Add paths to the source path... or one path... something like c:\flashclasses\as3
    Then inside your as3 folder you set your package folders. If you use TweenLite you'd have:
    com
         greensock
              TweenLite classes
    or your own:
    com
         myDomain
              my classes
    then you'd import like:
    import com.greensock.TweenLite;
    import com.myDomain.myClass;
    Make sense?

  • Drop java class not working

    Hello,
    i'm using a freshly installed SQLDeveloper 1.5.1 to a java class to the database. Loading the class works, i can see my class in the tree under java.
    Now i wanted to change the source code of my class, so i wanted to drop it in the database. But although SQLDeveloper tells me that the Java Object "MyClass" has been dropped, it is still there in the tree. When i click on the entry in the tree i can still see the code.
    What do i need to do to remove my java code from the database?
    Thanks for help in advance,
    Dirk

    Hi ,
    select XMLTOOLKIT option in Operation mapping and execute it.
    I am not sure we can call java program in XSLT Program,but alternative is copy the code and use it in XSLT mapping it self,that means your XSLT program will become with JAVA extensions.
    then in Operation mapping level select SAPXMLTOOL kit option and execute it. i hope it will work. if it is not working then you have deploy some JAXP files on server,because the way execution of XSLT Mpaping program got changed,like when eve you executing XSLT with extnasions( if you are not using XMLTOOL kit option) then you have to use latest version of JAXP.JDK files.
    Regards,
    Raj

  • Java Applets and multiple classes not working.

    I have tested my JApplet class alone to view its layout and to make sure it actually works. But once I add in my other classes, compile, jar, and test I get the error:
    java.lang.NoClassDefFoundError: AlakApp (wrong name: alak/codeFiles/AlakApp)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
    4)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:155)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:127)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:618)
            at sun.applet.AppletPanel.createApplet(AppletPanel.java:779)
            at sun.applet.AppletPanel.runLoader(AppletPanel.java:708)
            at sun.applet.AppletPanel.run(AppletPanel.java:362)
            at java.lang.Thread.run(Thread.java:619)My Directory contains these and only these:
    F:\alak\codeFiles:
      AlakApp.java
      Game.java
      Board.java
      Space.java
      index.html
      AlakGame.jarAll my classes are in the package alak.codeFiles.
    My .html file contains this:
    <HTML>
    <HEAD>
      <TITLE>ALAK</TITLE>
    </HEAD>
    <BODY>
      <applet code="AlakApp.class" archive="AlakGame.jar" width=400 height=200>
      Please use a Java compatible browser to see this.
      </applet>
      <br>
    </BODY>
    </HTML>These are they commands I am issuing:
    F:\alak\codeFiles>javac *.java
    F:\alak\codeFiles>jar -cvf AlakGame.jar *.class
    F:\alak\codeFiles>appletviewer index.htmlI've been trying many different things to narrow down what is going on. If you need to see my code let me know, but I've tested everything with a text-based user interface and they work.
    So does anyone know the cause of this error?

    Ok i rared the test and uploaded to rapidshare.. here is the link:
    http://rapidshare.com/files/76860865/test.rar.html
    But here is the code. They are in the directory /test/files/
    ADigit.java
    package test.files;
    public class ADigit
      private int value;
      public ADigit( int val )
       this.value = val;
      public String toString()
       return "" + this.value;
    }ADigitApp.java
    package test.files;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ADigitApp extends JApplet implements ActionListener
      private ADigit numeroUno;
      private int currentNum;
      private Container container;
      private javax.swing.JLabel jLabel;
      private javax.swing.JTextArea jTextArea;
      private javax.swing.JButton jButton;
      public void init()
        currentNum = 1;
        numeroUno = new ADigit( currentNum );
         container = getContentPane();
        container.setLayout( new BorderLayout() );
         jLabel = new javax.swing.JLabel();
         jTextArea = new javax.swing.JTextArea();
         jLabel.setText( "The Number is: " );
         jTextArea.setText( numeroUno.toString() );
         jButton = new javax.swing.JButton();
         jButton.setText( "New Number" );
        jButton.addActionListener( this );
         container.add( jLabel, BorderLayout.WEST );
         container.add( jTextArea, BorderLayout.CENTER );
         container.add( jButton, BorderLayout.EAST );
        setSize( 200, 200 );
      public void actionPerformed( ActionEvent e )
        this.currentNum++;
         numeroUno = new ADigit( this.currentNum );
         jTextArea.setText( numeroUno.toString() );
    }index.html
    <HTML>
    <HEAD>
      <TITLE>NUMBERSSSS</TITLE>
    </HEAD>
    <BODY>
      <applet code="ADigitApp.class" archive="NumberFun.jar" width=200 height=200>
      Please use a Java compatible browser to see this.
      </applet>
      <br>
    </BODY>
    </HTML>Commands:
    /test/files>javac *.java
    /test/files>jar -cvf NumberFun.jar *.class
    /test/files>appletviewer index.htmlThis example produces the same style of error.

  • Javac command line program can use class, need tomcat to do same

    This may be simple, but any assistance to a newby would be greatly aprreciated. I have a this class file:
    import java.io.*;
    public class OCrypt
    static public String getEncryptedText (String plainText)
    Runtime R;
    String _encryptedText = "";
    char[] someData = new char[16];
    R = java.lang.Runtime.getRuntime();
    try
    java.lang.Process P = R.exec("./OCrypt " + plainText
    InputStreamReader ISR = new InputStreamReader(P.getInputStream());
    ISR.read(someData);
    _encryptedText = new String(someData,0,11);
    catch (Exception e)
    _encryptedText = "***ERROR***";
    return (_encryptedText);
    Where ./OCrypt is a compiled program writtine in C in the same folder. A small test program calls the class and C code and works. Now for the tomcat part, I need to be able to call this code from tomcat. I know it has worked in the past on a much older version of tomcat. I need to figure out how to make it work on tomcat 5.5.9
    Thanks

    Thanks for the reply. Please bare with me. I am reading in the SAMS teach yourself book to know how to create the folder structure. I assumed this folder should be off of my WEB-INF/classes folder. See the full path below.
    Couple of things
    1 - Your class should be in a package. Otherwise you
    will have problems.I added the .class file to a package. Or at least I think I did. I added this line to the top of the code.
    package OCrypt;
    The file is in this folder:
    /var/local/jakarta-tomcat-5.5.9/webapps/ROOT/pss/WEB-INF/classes/OCrypt
    Then I ran 'javac OCrypt' in that folder.
    2 -
    Where ./OCrypt is a compiled program writtine in C
    I always keep the C file in the same location as the class. That may be a problem later when tomcat can resolve the class but then can't find that program. I hope that will generate a completely different error.
    in the same folder.
    In the same folder as what?
    The current working directory for Tomcat is normally
    [TOMCAT]/bin. Is that the folder you mean? I will put it there if I get the class resolved.
    If you want to use this tool, I would say put it in
    the PATH for the machine (so it can be found from
    anywhere) or use an absolute reference to it.I can put a complete path in the .java file before I compile if you think that will help.
    You> can't count on the working directory being where you
    think it is. But right now I would just like to create a simple class like adding two numbers together and returning a result. My larger issue is more of a server configuration. I am using a enterprise wide tomcat server and have been told EACH application folder has it's own classpath. I even attempted to write a JSP that would output my enviroment to a simple page. This didn't work because the env was only for the user, not the env AFTER all the startup scripts run for the server.
    >
    One solution is to use ServletContext.getRealPath().
    Is there any reason you couldn't rewrite the
    encryption into Java - that way you wouldn't have to
    bother with Runtime.exec()
    Another alternative would be to use JNI to get a Java
    interface to the C class.
    http://www-128.ibm.com/developerworks/edu/j-dw-javajni
    -i.html
    I think either of those solutions are preferable to
    using Runtime.exec().

  • Why does the child class need to implement the parent classes constructor?/

    As I was playing around with some code I came across this point :
    First Class
    public class A {
         public int x;
         A(int i){
              x=i;
              System.out.println("A is initialised");
    }Second Class extending it :
    public class B extends A{
         private int y;
       // Why do I need this constructor to call parents constructor?
      // My guess is so that when i make an object of class B referring to class A it should make sense?
         B(int i) {                     
              super(i); 
              y=test;
    public static void main(String args[]){
          A a = new A(1);
          A b = new B(1); make an object of class B referring to class A it should work!!
          B c = new B(2);
          B d =(B) new A(2);  --> gives class cast exception!
    }I am little confused here, Can someone throw more light on it.
    Thanks

    You don't override constructors. However, every class, in it's constructor, must call some constructor from the class it's extending. In most cases this is simply super(). However, if your class does not have a default constructor (i.e. you've declared any other constructor, or the sub class does not have access to it, I.E. you've declared it private) then you must include a call to some other constructor in the super class. The constructor in the subclass does not have to be the same as the super class one, but you do have to invoke a constructor from the super class. I.E.
    class A {
      A(int i) {}
    class B extends A {
      B(String b) {
        super(0);
    }

  • Abstract class needs to be observed

    Hi! Thank you for reading my post!
    I have been programming seriously in Java for two years now. But sometimes I still feel like I am a rookie.
    Here is the situation:
    Class A is a parent class. Subclasses B, C, and D extend A. Superclass A extends Observable, and thus it needs to notify its observers when it has changed. Superclass A has an abstract method, which is implemented by subclasses B, C, and D.
    Question:
    When the abstract method is invoked in subclasses B, C or D, can I somehow set Superclass A as 'changed' and 'notifyObservers' without having to make the 'changed' and 'notifyObservers' call in each of the subclasses B, C and D? In others words, is there a way to implement a non-abstract method (i.e. setChanged() or notifyObservers() ) inside of an abstract method (i.e. method() as shown below )?
    Reasoning:
    The reason that I want to avoid having to put this code into every subclass is because the subclasses may be created in the future without the programmer knowing that the subclass needs to notify of the change/update. I want to 'dummify' the programming for the future user. In addition, there are a lot of subclasses.
    Here is some code to help:
    Class A extends Observable
      public void abstract method();
    Class B extends A
      public void method()
        //do something here...
        //I want to avoid having to type these lines in every class
        //that extends Class A:
        setChanged();    // <-- can I avoid putting this here?
        notifyObservers();  // <-- can I put it in Class A's abstract method somehow?
    Class C extends A
      public void method()
        //do something here...
        //I want to avoid having to type these lines in every class
        //that extends Class A:
        setChanged();    // <-- can I avoid putting this here?
        notifyObservers();  // <-- can I put it in Class A's abstract method somehow?
    Class D extends A
      public void method()
        //do something here...
        //I want to avoid having to type these lines in every class
        //that extends Class A:
        setChanged();    // <-- can I avoid putting this here?
        notifyObservers();  // <-- can I put it in Class A's abstract method somehow?
    }Thanks for any suggestions you might have!
    Regards,
    Julia

    OK. HMMM. Maybe I figured this out. Will this work?
    (Sometimes I really feel like a rookie! ;) )
    Class A extends Observable
      public void method()
        this.method2()
        this.setChanged();
        this.notifyObservers();
      public void abstract method2();
    Class B extends A
      public void method2()
        //do something here ....
    Class C extends A
      public void method2()
        //do something here ....
    Class D extends A
      public void method2()
        //do something here ....
    }Ok - well, thanks anyways. I think this will work. Now I really feel stupid for even bothering to post. Oh well.
    Hope you have a great day!
    Thanks!
    Julia

Maybe you are looking for

  • How to find out the destination of an "Adaptive RFC Model - DEPRECATED"

    Hi All, How to find out the destination of an "Adaptive RFC Model - DEPRECATED" of an running application and Where is the destination created in the server . I have got the code of the running project from NWDI . Thanks in Advance Regards Piyas Kuma

  • How do I install Capivate 7 on a server?

    How do I install Capivate 7 on a server?

  • Mac OS 10.4.8 - 10..4.10 crash apps on print

    The second time I print from an application (without shutting it down) inevitably causes a crash. Can anyone figure out what this message from Console means: CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.

  • How to import Excisable items through DTW

    Hi Experts, How i can import the excisable items through DTW,  In which column of Oitem Template i have to mention that Item is excisable or not. Thanks & Regards, Pankaj Sharma

  • No Color Profile

    I'm trying to sync my color profile with the CS3 apps. The help tells me to go under Preferences >> Advanced and select "Enable Color Management In Bridge". It is not there to select. Any ideas?