on 03-23-2009 1:42 PM
Hi Experts,
Is there any possible to validate Special characters(!,@,#,$,%,^,&,*,(,),,,,,etc) in Input field? If Possible How to do that?
Regards,
Manivannan P
Hello,
You can validate those required characters in action handler.
You can put your validattion code like
if(currentchar == '@' || currentchar == '$' ......)
post some message
else
sucess
I hope this would resolve your problem.
Regards,
Pankaj Sharma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
You can try the following code to validate the special characters using regular expressions :
for example : The following example validates that the string can only contain alphanumeric characters, asteric sign
String input = "input%Sttring"
boolean dec=input.matches(("[^&]([\\p{Alnum}\\s\\-.*])*") ) ;
Therefore the "input" string will fail the validation as the input string contains "%" which is not permitted.
There are so many special characters and therefore you need to add in the regular expression what you want to permit in the string
Thanks
Ritushree
Edited by: Ritushree Saha on May 27, 2009 1:02 PM
Edited by: Ritushree Saha on May 27, 2009 1:03 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this below code. It works.
String str="abcd$%e1**";
String regexpChars = "^[a-zA-Z0-9]{1,}$";
Matcher matcher;
Pattern pattern = Pattern.compile(regexpChars);
matcher = pattern.matcher(str);
if(!matcher.matches())
{
System.out.println("Special Characters exists in string..");
}
Imports required:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Regards,
Charan
hi
you can either go for patter matching for validating specialc characters or
you can get the Ascii values for the special characters and validate them
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi expert ..
you can use this code to solve yoour proble..try to use this code..
public void validate()
{
String aspc="asas222#";
boolean dec=aspc.matches(("[^&]([
p{Alnum}
s
])") ) ;
System.out.println("dec"+dec);thanks
jati
Edited by: sudhir kumar on Mar 25, 2009 6:28 AM
Edited by: sudhir kumar on Mar 25, 2009 6:29 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The formatting has been changed after posting.So am again sending same with striking the line.
boolean dec=input.matches(("[^&]([
p
s
-.])") ) ;
Thanks
Kanai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Create one function like validate with returntype boolean
public boolean validate( )
{
// get the value from text field from View
String input=wdContext.current[node]Element().get[context attribute]()
boolean dec=input.matches(("[^&]([
p{Alnum}
s
-.])") ) ;
return dec;
}
You need to call this function either from the any of your button action or onEnter of text.
Suppose your button action or onEnter of text function is Search().
Then you just write only that code.
public void onActionSearch(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
IWDMessageManager msgMgr = wdThis.wdGetAPI().getComponent().getMessageManager();
if(validateInput()){
//Then do further processing
}
else
msgMgr.raiseException("Please remove special character in search field",true);
}
Hope this will resolve your problem
Thanks
Kanai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi expert
suppose your string p
String str=sudhira!jati.com;
boolean validate=str.matches(("([
p!@#$%&,*])") );
hope is work
thanks
jati
Edited by: sudhir kumar on Mar 24, 2009 9:34 AM
Edited by: sudhir kumar on Mar 24, 2009 9:36 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Manivannan,
You can use Pattern & Matcher classes from java.util.regex package.
Refer java docs at http://java.sun.com/j2se/1.4.2/docs/api/index.html
Kind Regards,
Nitin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Use this [thread|; for help that how it will work , Go to reply (code below )which I have provided
if (attributeValue instanceof String)
{
if (((String) attributeValue).length() == 0)
It is just one condition that if length ==0 then display the error message in the same way we can put condision
for special characters.
[Hint|http://www.javapractices.com/topic/TopicAction.do?Id=96] is : we have to take the help of java classes how it deal with special characters . But still u feel problem then revert back I ll write it for u.
Best Regards
Satish Kumar
Edited by: satish jhariya on Mar 23, 2009 7:37 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.