Textbox Input Restricting

Hello,

I want to limit what can be typed into a textbox. Specifically to only allow numbers. and maybe even a maximum/minimum number size. Would this done with a regex? Or which function is used to do this.

Thank you.

3 Replies

PJ Pravin Joshua D Syncfusion Team July 5, 2010 10:05 AM UTC

Hi Theo,

Thank you for using Essential PDF.

Form field validation can be done using PdfJavascriptAction. Please add the required PdfJavaScript in the validate event of the form field. This javascript will be executed whenever the value has been entered to the field. Please have a look at the sample code snippet below to add javascript in the form field validate event.

[C#]:

//Define the form field
PdfTextBoxField text = new PdfTextBoxField(page,"Text1");

// Add validation javascript
text.Actions.Validate = new PdfJavaScriptAction("app.alert(\"You are looking at Java script action of PDF \")");

// Define the field bounds and properties
text.Bounds = new RectangleF(100,100,100,100);
text.BorderColor = new PdfColor(Color.Red);

//Add the form field to the document
doc.Form.Fields.Add(text);

Please try this and let us know if you have any questions.

Regards,
Pravin.


TH Theo March 15, 2011 07:54 PM UTC

Hello,

I am having issues with the actual javascript. I want to restrict the input to only allow numbers in the textbox.

The error I am getting is "Input string was not in a correct format".

The javascript im using is directly from the adobe guide here. Page 84. "http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_developer_guide.pdf"

Any suggestions? Is the javascript handled differently in Syncfusion?


if ( event.willCommit ) {
var value = ""+event.value.replace(/\s*/g,"");
if ( value != "" ) {
if (!isFinite(value)) {
app.beep(0);
event.rc = false;
}
}
} else if ( event.change == " " ) {
event.change = "";
}





GM Geetha M Syncfusion Team March 16, 2011 05:59 AM UTC

Hi Theo,

Thank you for your interest in Syncfusion products.

I am afraid that I am not able to reproduce the exception. I am able to insert a JavaScript Action to 'Validate' and I have placed my test sample in the following link:
F95305444178973.zip

Could you please try running the above sample and let me know about it?

Regards,
Geetha


Loader.
Up arrow icon